syft.core.common

class syft.core.common.ObjectWithID(id=None)[source]

Bases: syft.core.common.serde.serializable.Serializable

This object is the superclass for nearly all Syft objects. Subclassing from this object will cause an object to be initialized with a unique id using the process specified in the UID class.

Note

At the time of writing, the only class in Syft which doesn’t have an ID of some kind is the Client class because it’s job is to point to another object (which has an ID).

Note

Be aware of performance choices in this class because it is used so heavily across the entire codebase. Assume every method is going to be called thousands of times during the working day of an average data scientist using syft (and millions of times in the context of a machine learning job).

__init__(id=None)[source]

This initializer only exists to set the id attribute, which is the primary purpose of this class. It also sets the ‘as_wrapper’ flag for the ‘Serializable’ superclass.

Parameters

id – an override which can be used to set an ID for this object

property id

We reveal ObjectWithID.id as a property to discourage users and developers of Syft from modifying .id attributes after an object has been initialized.

Returns

returns the unique id of the object

repr_short()[source]

Return a SHORT human-readable version of the ID which makes it print nicer when embedded (often alongside other UID objects) within other object __repr__ methods.

Returns

a SHORT human-readable version of SpecificLocation

static get_protobuf_schema()[source]

Return the type of protobuf object which stores a class of this type

As a part of serialization and deserialization, we need the ability to lookup the protobuf object type directly from the object type. This static method allows us to do this.

Importantly, this method is also used to create the reverse lookup ability within the metaclass of Serializable. In the metaclass, it calls this method and then it takes whatever type is returned from this method and adds an attribute to it with the type of this class attached to it. See the MetaSerializable class for details.

Returns

the type of protobuf object which corresponds to this class.

class syft.core.common.UID(value=None)[source]

Bases: syft.core.common.serde.serializable.Serializable

A unique ID for every Syft object.

This object creates a unique ID for every object in the Syft ecosystem. This ID is guaranteed to be unique for the node on which it is initialized and is very likely to be unique across the whole ecosystem (because it is long and randomly generated).

Nearly all objects within Syft subclass from this object because nearly all objects need to have a unique ID. The only major exception a the time of writing is the Client object because it just points to another object which itself has an id.

There is no other way in Syft to create an ID for any object.

__init__(value=None)[source]

Initializes the internal id using the uuid package.

This initializes the object. Normal use for this object is to initialize the constructor with value==None because you want to initialize with a novel ID. The only major exception is deserialization, wherein a UID object is created with a specific id value.

Parameters

value (uuid.uuid4, optional) – if you want to initialize an object with a specific UID, pass it in here. This is normally only used during deserialization.

Returns

returns the initialized object

Return type

UID

from syft.core.common.uid import UID
my_id = UID()
repr_short()[source]

Returns a SHORT human-readable version of the ID

Return a SHORT human-readable version of the ID which makes it print nicer when embedded (often alongside other UID objects) within other object __repr__ methods.

static get_protobuf_schema()[source]

Return the type of protobuf object which stores a class of this type

As a part of serialization and deserialization, we need the ability to lookup the protobuf object type directly from the object type. This static method allows us to do this.

Importantly, this method is also used to create the reverse lookup ability within the metaclass of Serializable. In the metaclass, it calls this method and then it takes whatever type is returned from this method and adds an attribute to it with the type of this class attached to it. See the MetaSerializable class for details.

Returns

the type of protobuf object which corresponds to this class.

Return type

GeneratedProtocolMessageType

Modules

syft.core.common.environment

syft.core.common.event_loop

syft.core.common.group

syft.core.common.message

syft.core.common.object

syft.core.common.pointer

syft.core.common.serde

Tutorial: Serialization and Deserialization in Syft

syft.core.common.storeable_object

syft.core.common.uid