Skip to main content

Asyncio grpclib SDK for afs_proxy/afslet

Project description

Python Async SDK (grpclib)

This SDK talks to afs_proxy / afslet using asyncio + grpclib. Generated protobuf modules are inside afs_sdk/api/....

Version

When imported from a git checkout, afs_sdk.__version__ is resolved from:

git describe --tags --long --always --dirty --match 'v*'

Example output:

>>> import afs_sdk
>>> afs_sdk.__version__
'v0.2.0-1-gabc1234-dirty'
>>> afs_sdk.get_version_info()
VersionInfo(version='v0.2.0-1-gabc1234-dirty', tag='v0.2.0', commit_sha='abc1234', distance=1, dirty=True)

When installed from a built distribution without .git metadata, it falls back to the package metadata version. PyPI release versions are derived from git tags via setuptools_scm.

Setup (uv)

cd python
~/.local/bin/uv sync

API

  • Low-level: AfsClient.raw_execute(requests: AsyncIterator[ExecuteRequest])
  • High-level: AfsClient.execute(request: ExecuteInput)
    • request is a single typed object (image, optional command, resources, and extra file entries)
    • set force_local_fetch=True to force local layer fetch on selected layerstore
    • response is AsyncIterator[ExecuteEvent]
  • Proxy status stream: AfsClient.status(include_layerstores=True, include_afslets=True)
    • returns AsyncIterator[ProxyStatusEvent]
  • Reconcile image replica: AfsClient.reconcile_image(request: ReconcileImageInput)
    • request: image/tag/platform/replica
    • response: ReconcileImageResult(image_key, current_replica, requested_replica, ensured)
  • Execute tar.gz output is parsed in streaming form into:
    • TarDirectory
    • TarSymlink
    • TarFilePart (chunked file data; no full-file buffering)
  • CPU-heavy tar.gz decode/untar is offloaded via executor:
    • pass tar_executor=... to AfsClient
    • default is an internal ThreadPoolExecutor(max_workers=1)

Extra file input types

ExtraFile.content supports:

  • bytes
  • AsyncIterator[bytes]

Example

import asyncio
from afs_sdk import AfsClient, ExecuteInput, ExtraFile

async def run():
    req = ExecuteInput(
        image="alpine",
        tag="latest",
        command=["/bin/sh", "-c", "echo ok >/tmp/ok.txt"],
        cpu_cores=1,
        memory_mb=256,
        timeout_ms=2000,
        extra_entries=[
            ExtraFile(path="hello.txt", content=b"hello from sdk\n"),
        ],
    )

    async with AfsClient("127.0.0.1", 62051) as client:
        async for event in client.execute(req):
            print(type(event).__name__)

asyncio.run(run())

CLI-style demo:

PYTHONPATH=python ~/.local/bin/uv run python python/examples/execute_stream.py \
  --addr 127.0.0.1:62051 \
  --dir ./extra-dir \
  --image alpine --tag latest \
  -- /bin/sh -c 'echo ok >/tmp/ok.txt'

If command is omitted, AFS uses the image Entrypoint/Cmd defaults returned by discovery.

Reconcile image replica demo:

PYTHONPATH=python ~/.local/bin/uv run python python/examples/reconcile_image.py \
  --addr 127.0.0.1:62051 \
  --image alpine --tag latest --replica 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afs_sdk-0.2.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afs_sdk-0.2.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file afs_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: afs_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for afs_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d4b1ae18536b4654fb9589fb242ef0990f1f502d0b0df653917b75d83cdba693
MD5 253ef343a0cb3a2ea77b8b7b0839912b
BLAKE2b-256 f3c67b3fa26656ec473a50de7d59aa1c4d8a10ada350e0a7d1e3eac8e260ba4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for afs_sdk-0.2.1.tar.gz:

Publisher: python-publish.yml on reyoung/afs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file afs_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: afs_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for afs_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28354d4c1e459e98865073625d436ba4086ee9cb60bea0b64da4c7cbdf220363
MD5 9866dcde34c9422349c13cfec2441d88
BLAKE2b-256 a888da423cd293fb6017a4dbfd472413adc3ef4752d5f498f85d98e904fa642b

See more details on using hashes here.

Provenance

The following attestation bundles were made for afs_sdk-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on reyoung/afs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page