Send pydicom.dataset.FileDataset to orthanc instance from Python

I am implementing the following pipeline:

  1. remote-dicom-server → 2) local-dicom-server (Orthanc) → 3) python processing → 4) local-dicom-server (same as on step 2) → remote-dicom-server (same as on step 1)

I learn how to do all the steps, but I want to reduce time consumption at step 4). Currently after processing the Series in python (step 3) I save it on disk and then use Orthanc API to send it to local-dicom-server.
Is there any way to avoid using storing result on disk and send it to local-dicom-server directly from Python?

I figured out it should be something like this

curl -X POST http://localhost:8042/instances --data-binary @CT.X.1.2.276.0.7230010.dcm

except instead of @CT.X.1.2.276.0.7230010.dcm I want to send pydicom.dataset.FileDataset object.

I tried to convert pydicom.dataset.FileDataset to bytes and use DoPost from RestToolbox.py (pass byte-sequence as data), but it does not work

In case someone encounter this problem, I end up writing a small function (using Orthanc API):

h = httplib2.Http()

h.add_credentials(user, password)

headers = {‘content-type’ : ‘application/dicom’}
content = bytes_sequence # pydicom.dataset.FileDataset coverted to bytes
URL = ‘127.0.0.1:8880/instances
resp, content = h.request(URL, ‘POST’, body = content, headers = headers)