Question: How can I send a large IFC file from a local dir to the speckle server using python

Hi Everyone,
I’m quite new to Speckle and i’m trying to look for a way to send (large) ifc-files to the Speckle server using python. I can find a lot of documentation about using an ifc-parser written in js but none of which showing examples written in python. Does such examples/modules/packages exist? Please help to guide me on which resources i can call opun for more information regarding this task (and what other possibilities might be available).

Thank you.

Donny

Hey @DonnyRH, welcome to the Speckle Community. You’ve caught many of us taking a short hiatus, so I’m sorry your question wasn’t answered in the expected timeframe.

Uploading any file supported for conversion (ifc, ETL, obj) to the file import service endpoint will trigger a conversion and subsequent version commit to a Speckle project stream.

So, the most straightforward method from any Python script is to POST the binary data to the streams/$STREAM_ID/uploads endpoint of your preferred Speckle server, which will perform the parsing for you.

@jonathon Thank you very much for the reply. The code below shows my attempt of sending the binairy data of a certain file to a chosen endpoint. But it seems like i’m missing something in the proces. Can you see what i’m missing?

Code:

endpoint='https://app.speckle.systems/projects/34c867fXXX/streams/34c867XXX/uploads'

files={
     "file": (open(filepath,'rb').read())
}


headers={
    "Authorization" :"{}".format(token)
}

response=requests.post(url=endpoint,headers=headers,files=files)
        
if response.status_code == 200:
    print(response.json())

else:
    response= response.text
    print(response)

Apologies again, the dangers of answering from memory while mobile…

“{serverUrl}/api/file/autodetect/{streamId}/{branchName}"

Is more like the endpoint in fact.

@jonathon Thanks a lot! The code below worked for me.

endpoint='https://app.speckle.systems/api/file/autodetect/34c867XXX/main'

files={
    "file": (open(filepath,'rb'))
}

headers={
    "Authorization" :"{}".format(token)
}

response=requests.post(url=endpoint,headers=headers,files=files)
        
if response.status_code == 200:
    print(response.content)


else:
    response= response.text
    print(response)
1 Like

Great. Lessons learned, if I am keen to help in the holidays, at least get it right :joy:

2 Likes