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)
>>>
>>> atmo = Atmosphere.login("handle", "password")
>>>
>>> publisher = LensPublisher(atmo)
>>> uri = publisher.publish(
...     name="my_lens",
...     source_schema_uri="at://did:plc:abc/ac.foundation.dataset.schema/source",
...     target_schema_uri="at://did:plc:abc/ac.foundation.dataset.schema/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,
    code_repository,
    code_commit,
    getter_path,
    putter_path,
    description=None,
    language=None,
    metadata=None,
    rkey=None,
)

Publish a lens transformation record to ATProto.

Code references are required by the ATProto lexicon. Each lens must point to a getter and putter implementation in a git repository.

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
code_repository str Git repository URL containing the lens code. required
code_commit str Git commit hash for reproducibility. required
getter_path str Module path to the getter function (e.g., ‘mymodule.lenses:my_getter’). required
putter_path str Module path to the putter function (e.g., ‘mymodule.lenses:my_putter’). required
description Optional[str] What this transformation does. None
language Optional[str] Programming language (e.g., ‘python’). None
metadata Optional[dict] Arbitrary metadata dictionary. None
rkey Optional[str] Optional explicit record key. None

Returns

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

publish_from_lens

atmosphere.LensPublisher.publish_from_lens(
    lens_obj,
    *,
    name,
    source_schema_uri,
    target_schema_uri,
    code_repository,
    code_commit,
    description=None,
    language=None,
    metadata=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
language Optional[str] Programming language (e.g., ‘python’). None
metadata Optional[dict] Arbitrary metadata dictionary. None
rkey Optional[str] Optional explicit record key. None

Returns

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