LensPublisher

atmosphere.LensPublisher(client)

Publishes Lens transformation records to ATProto.

This class creates lens records that reference source and target schemas and point to the transformation code in a git repository.

Examples

>>> @atdata.lens
... def my_lens(source: SourceType) -> TargetType:
...     return TargetType(field=source.other_field)
>>>
>>> client = AtmosphereClient()
>>> client.login("handle", "password")
>>>
>>> publisher = LensPublisher(client)
>>> uri = publisher.publish(
...     name="my_lens",
...     source_schema_uri="at://did:plc:abc/ac.foundation.dataset.sampleSchema/source",
...     target_schema_uri="at://did:plc:abc/ac.foundation.dataset.sampleSchema/target",
...     code_repository="https://github.com/user/repo",
...     code_commit="abc123def456",
...     getter_path="mymodule.lenses:my_lens",
...     putter_path="mymodule.lenses:my_lens_putter",
... )

Security Note

Lens code is stored as references to git repositories rather than inline code. This prevents arbitrary code execution from ATProto records. Users must manually install and trust lens implementations.

Methods

Name Description
publish Publish a lens transformation record to ATProto.
publish_from_lens Publish a lens record from an existing Lens object.

publish

atmosphere.LensPublisher.publish(
    name,
    source_schema_uri,
    target_schema_uri,
    description=None,
    code_repository=None,
    code_commit=None,
    getter_path=None,
    putter_path=None,
    rkey=None,
)

Publish a lens transformation record to ATProto.

Parameters

Name Type Description Default
name str Human-readable lens name. required
source_schema_uri str AT URI of the source schema. required
target_schema_uri str AT URI of the target schema. required
description Optional[str] What this transformation does. None
code_repository Optional[str] Git repository URL containing the lens code. None
code_commit Optional[str] Git commit hash for reproducibility. None
getter_path Optional[str] Module path to the getter function (e.g., ‘mymodule.lenses:my_getter’). None
putter_path Optional[str] Module path to the putter function (e.g., ‘mymodule.lenses:my_putter’). None
rkey Optional[str] Optional explicit record key. None

Returns

Name Type Description
AtUri The AT URI of the created lens record.

Raises

Name Type Description
ValueError If code references are incomplete.

publish_from_lens

atmosphere.LensPublisher.publish_from_lens(
    lens_obj,
    *,
    name,
    source_schema_uri,
    target_schema_uri,
    code_repository,
    code_commit,
    description=None,
    rkey=None,
)

Publish a lens record from an existing Lens object.

This method extracts the getter and putter function names from the Lens object and publishes a record referencing them.

Parameters

Name Type Description Default
lens_obj Lens The Lens object to publish. required
name str Human-readable lens name. required
source_schema_uri str AT URI of the source schema. required
target_schema_uri str AT URI of the target schema. required
code_repository str Git repository URL. required
code_commit str Git commit hash. required
description Optional[str] What this transformation does. None
rkey Optional[str] Optional explicit record key. None

Returns

Name Type Description
AtUri The AT URI of the created lens record.