PySpeckle: Stream Object Does Not Contain Data

Hi All,

I’m looking into streaming data with PySpeckle to my speckle server. I am able to pull the data of a stream with the StreamGetObjectAsync ({STREAM_ID}) method.

Now I am looking into streaming data a simple dictionary to my server and it seems to be working according to my terminal, but the data is not showed in the stream objects on my server…

Anyone who can be of help?

@TomSvilans can you be of help?

Hi @dirksliepenbeek, it looks like you are creating a stream with your object data, instead of uploading the object to an existing stream.

First make the stream (as you are doing), and then upload the object to that stream with client.ObjectCreateAsync(<list of objects>) or client.objects.create().

1 Like

Thanks for the quick reply. I just tried the approach you’re describing, is this what you mean? The objects are not yet part of the stream.

1 Like

Try something like this:

placeholders = []

# Objects is the list of your objects
for object in objects:
    res = client.ObjectCreateAsync([object])['resources'][0]
    placeholders.append({'type':'Placeholder', '_id':res['_id']})

res = client.StreamGetAsync(streamId)

stream = res['resource']
stream['layers'][-1]['objectCount'] = len(placeholders)
stream['layers'][-1]['topology'] = "0-%s" % (len(placeholders))

res = client.StreamUpdateAsync(stream['streamId'], {'objects':placeholders, 'layers':stream['layers']})

If you update PySpeckle to the latest version, this should work even easier:

import speckle
from speckle import SpeckleApiClient
import speckle.schemas

client = SpeckleApiClient()

# Login
client.login(email="speckle@works.com", password="speckle<3")

# Create a new stream locally
stream = speckle.resources.streams.Stream()
stream.name = "A Nice Stream"
stream.tags = ["cool", "amazing", "nice"]

# Create a SpeckleMesh
sm = speckle.schemas.Mesh()
sm.vertices = [0,0,0,1,0,0,1,1,0,0,1,0]
sm.faces=[1,0,1,2,3]
sm.name = "A Wonderful Mesh"

# Create the object on the server and receive a placeholder in return
placeholders = client.objects.create(sm)

# Add the placeholders to the stream object list
stream.objects = placeholders

# Create the stream on the server
res = client.streams.create(stream)
1 Like

First thing I do tomorrow! Looks more clear I have to say :slightly_smiling_face:

@TomSvilans - This does the job, much thanks!

I was wondering how to access objects in the schema like the Number / String, I see that these are implemented at the moment, but when I try something like speckle.schemas.Number() it is not possible.

Now I just used a workaround in which I use speckle.schemas.Null() and change the type to a number, but I not sure if that is the way to go.

image

Yeah, I need to look at this a bit more closely. The dynamic schema loading is still in the works, but we’ll figure it out. For now you can try from speckle.schemas import Mesh, Null, Line, etc. and then just use it like mesh = Mesh().

There is no schema for Number yet. You can see what schemas are currently implemented in the speckle.schemas folder.

Alright. Just noticed that it’s quite straight forward to implement new speckle.schemas. Do you know where I can find the definitions for the different SpeckleObjects? If I have those I can just start adding the ones I need correctly.

Hang on, but why do you need separate schemas for Number and String? These are just basic types which are used all over…

I thought that was needed to stream it to Speckle. I noticed that not every schema is containing the same data-fields. For example, for the number, there is a “value” key, which I was missing at the speckle.schemas.Null(). So I thought if I just add Number.py with the datafields related to a SpeckleNumber than my issue is solved.

However, from your comment, I understand that I’m not really on the right track with that, happy to hear what would be the better approach.

Ah, so you want to upload a single number to the server with an ID? Can you describe a little bit more what you’re aiming for?

BTW the Speckle API docs with all the schemas are here: https://speckleworks.github.io/SpeckleSpecs/#schemas

As part of an exploratory research I’m looking into streaming plain data to Speckle. I can imagine a workflow where we have some output of a Python tool, and we want to push that directly to Speckle to later pull it out in Dynamo / Revit / Grasshopper or something like that.

Trying to reproduce something like this.

Hope you can see this:

https://maritime-research.speckle.rhdhv.digital/api/streams/APEqHqANw/objects

Ah ok, yes, this should be trivial to implement.

If you don’t want to wait until it goes through the PR process on the official PySpeckle repo, you can grab an update from here: https://github.com/tsvilans/PySpeckle

Just download the repo as a .zip, and replace your speckle folder with the speckle folder in the archive.

Hi @dirksliepenbeek, the Number and String schemas are now merged into the master repo, so feel free to update with pip.

1 Like