Skip to content

Link

Bases: Entity

Represents a link in Synapse.

Links must have a target ID and a parent. When you do synapseclient.Synapse.get on a Link object, the Link object is returned. If the target is desired, specify followLink=True in synapseclient.Synapse.get.

ATTRIBUTE DESCRIPTION
targetId

The ID of the entity to be linked

targetVersion

The version of the entity to be linked

parent

The parent project or folder

properties

A map of Synapse properties

annotations

A map of user defined annotations

local_state

Internal use only

Using this class

Creating an instance and storing the link

link = Link('targetID', parent=folder)
link = syn.store(link)
Source code in synapseclient/entity.py
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
class Link(Entity):
    """
    Represents a link in Synapse.

    Links must have a target ID and a parent. When you do [synapseclient.Synapse.get][] on a Link object,
    the Link object is returned. If the target is desired, specify followLink=True in synapseclient.Synapse.get.

    Attributes:
        targetId: The ID of the entity to be linked
        targetVersion: The version of the entity to be linked
        parent: The parent project or folder
        properties: A map of Synapse properties
        annotations: A map of user defined annotations
        local_state: Internal use only


    Example: Using this class
        Creating an instance and storing the link

            link = Link('targetID', parent=folder)
            link = syn.store(link)
    """

    _property_keys = Entity._property_keys + ["linksTo", "linksToClassName"]
    _local_keys = Entity._local_keys
    _synapse_entity_type = "org.sagebionetworks.repo.model.Link"

    def __init__(
        self,
        targetId=None,
        targetVersion=None,
        parent=None,
        properties=None,
        annotations=None,
        local_state=None,
        **kwargs,
    ):
        if targetId is not None and targetVersion is not None:
            kwargs["linksTo"] = dict(
                targetId=utils.id_of(targetId), targetVersionNumber=targetVersion
            )
        elif targetId is not None and targetVersion is None:
            kwargs["linksTo"] = dict(targetId=utils.id_of(targetId))
        elif properties is not None and "linksTo" in properties:
            pass
        else:
            raise SynapseMalformedEntityError("Must provide a target id")
        super(Link, self).__init__(
            concreteType=Link._synapse_entity_type,
            properties=properties,
            annotations=annotations,
            local_state=local_state,
            parent=parent,
            **kwargs,
        )