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.

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

I tried to convert pydicom.dataset.FileDataset to bytes and use DoPost from (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 = ‘
resp, content = h.request(URL, ‘POST’, body = content, headers = headers)