literegistry-podman-client
literegistry-podman-client is a small, standalone async Python client for
running commands in rootless Podman containers through a LiteRegistry gateway.
The person using it needs only a gateway URL; they do not need Redis, Podman,
Docker, or the full literegistry package.
The same gateway may also expose a Docker Hub pull-through mirror. Mirror use
is configured on the Podman servers by the operator, so client code still only
passes a normal image such as docker.io/library/ubuntu:24.04.
Install
Install through the LiteRegistry extra:
pip install "literegistry[podman_client]"
The standalone distribution is also available directly:
pip install literegistry-podman-client
From this repository:
pip install ./literegistry_podman_client
The distribution name uses hyphens. Python imports use underscores:
from literegistry_podman_client import PodmanClient
Its runtime dependencies are aiohttp and Python Fire.
Give a deployment to someone
The operator gives the user one value:
export PODMAN_GATEWAY_URL=http://gateway.example:8080
The user can verify both gateway features:
curl -fsS "$PODMAN_GATEWAY_URL/health"
curl -fsS "$PODMAN_GATEWAY_URL/v2/"
/health checks the LiteRegistry gateway. /v2/ checks its Docker Registry
V2 mirror route. No Redis URL or Podman replica address is exposed to users.
Small async example
This creates one container, writes a file, reads it in a separate command, and always deletes the container at the end:
Without async with
import asyncio
from literegistry_podman_client import PodmanClient
async def main() -> None:
gateway_url = "http://gateway.example:8080"
client = PodmanClient(gateway_url, workdir="/tmp")
podman = None
await client.open()
try:
podman = await client.handshake(
image="docker.io/library/ubuntu:24.04",
client_id="rollout-17",
)
print(podman.container_id)
await podman.execute("echo ai2 hello > hello.txt", check=True)
result = await podman.execute("cat hello.txt", check=True)
print(result.stdout, end="")
finally:
try:
if podman is not None:
await podman.close()
finally:
await client.aclose()
asyncio.run(main())
With async with
import asyncio
from literegistry_podman_client import PodmanClient
async def main() -> None:
async with PodmanClient(
"http://gateway.example:8080",
workdir="/tmp",
) as client:
async with client.session(
image="docker.io/library/ubuntu:24.04",
client_id="rollout-17",
) as podman:
print(podman.container_id)
await podman.execute("echo ai2 hello > hello.txt", check=True)
result = await podman.execute("cat hello.txt", check=True)
print(result.stdout, end="")
asyncio.run(main())
The image pull happens on the selected Podman replica. If the operator wired those replicas to the gateway's mirror, the pull is transparently cached; the user does not change the image reference or client configuration.
The installed Fire CLI exposes the same smoke test:
literegistry-podman-client ai2-hello --gateway="$PODMAN_GATEWAY_URL"
The runnable version is examples/ai2_hello.py:
python literegistry_podman_client/examples/ai2_hello.py \
--gateway "$PODMAN_GATEWAY_URL"
Terminal sandbox loss
With client 0.1.4, PodmanContainerLostError signals that the current sandbox
cannot be used again. Catch it at the episode boundary; do not silently create a
replacement container and continue the same episode. The client does not
re-handshake automatically.
from literegistry_podman_client import PodmanContainerLostError
try:
result = await session.execute(command)
except PodmanContainerLostError as exc:
# End or discard this episode according to the training policy.
# A fresh session belongs to a new episode.
print(exc.reason, exc.limit, exc.observed, exc.enforcement)
raise
A confirmed loss marks PodmanSession.closed true. Later execute() calls raise
the same typed error locally, and close() is a no-op. An already-lost response
during close is also treated as successful cleanup. Low-level
client.execute(affinity_id, ...) raises the typed error but retains no per-session
state; callers using that API must stop submitting commands for the lost ID.
LiteRegistry 1.0.52 returns HTTP 410 with a detail object containing
code="sandbox_lost", recoverable=false, the container ID, and the watchdog
reason (memory_limit or pids_limit). limit, observed, and unit carry the
confirmed measurement; enforcement="userspace_watchdog" distinguishes this from
a kernel OOM. Memory observations are approximate aggregate RSS, not native
cgroup accounting.
Reasons are retained in memory on the owning replica for one hour, capped at
10,000 records. They are lost on replica restart or eviction. The client also
recognizes gateway 410 affinity_owner_lost and legacy structured
404 container_not_found responses, including FastAPI's detail envelope.
Legacy missing-container responses have reason unknown, not memory_limit.
Generic 404/503 responses and ordinary command failures remain gateway/command
errors; they do not prove permanent sandbox loss. In-flight requests already
sent before a loss is observed cannot be recalled.
Explicit lifecycle
Handshake, execute, and close are all async. The affinity ID returned by the handshake keeps every command on the replica that owns its container.
client = PodmanClient(gateway_url, workdir="/home/user")
await client.open()
session = None
try:
session = await client.handshake(image=container_image)
first = await client.execute(
session.affinity_id,
"python -c 'print(6 * 7)'",
timeout=60,
)
first.check_returncode()
finally:
try:
if session is not None:
await session.close()
finally:
await client.aclose()
client.close(affinity_id)orsession.close()deletes the container and its gateway affinity binding.client.aclose()only closes the local HTTP connection pool. It cannot guess which concurrent sessions should be deleted.check=Trueorresult.check_returncode()raisesPodmanCommandErrorfor a non-zero command exit. Without it, stdout, stderr, and the exit code remain available onCommandResult.result.stdout_truncatedandresult.stderr_truncatedreport whether the server discarded output beyond its configured capture limits. Always check these flags before treating captured output as complete.
Concurrent trajectories
One PodmanClient is intentionally shareable. It does not store a
private "current container". Each handshake returns a separate session:
async def rollout(client: PodmanClient, number: int) -> str:
podman = await client.handshake(client_id=f"rollout-{number}")
try:
result = await podman.execute("echo $((20 + 22))", check=True)
return result.stdout.strip()
finally:
await podman.close()
client = PodmanClient(gateway_url)
await client.open()
try:
outputs = await asyncio.gather(
*(rollout(client, i) for i in range(128))
)
finally:
await client.aclose()
The HTTP pool is shared, while every request carries its explicit affinity ID. As soon as one trajectory completes, application code may start another.
Mirror behavior
There are two distinct flows behind the gateway URL:
Python client -> /affinity/* -> Podman replica -> rootless container
Podman pull -> /v2/* -> Docker mirror -> Docker Hub
The client exposes await client.mirror_health() as a convenience probe, but
it does not configure the mirror. The deployment operator configures each
Podman replica's containers-registries.conf to use the gateway URL. This is
what ensures all users of the gateway benefit from the cache.
Build and publish
cd literegistry_podman_client
python -m build
python -m twine check dist/*
python -m twine upload dist/*
Publishing requires a PyPI account and token. Verify that the distribution
name literegistry-podman-client is available before the first upload.
Shared gateway discovery
Share one GatewayDiscovery across clients in the same event loop (or use one
PodmanClient for all trajectories). Discovery runs once, concurrent callers
share the result, and successful gateways have no refresh TTL:
from literegistry_podman_client import GatewayDiscovery, PodmanClient
# Requires `literegistry` in addition to this standalone client package.
discovery = GatewayDiscovery.from_registry(
"redis://registry:6379", endpoint_name="gateway"
)
async with PodmanClient(gateway_discovery=discovery) as client:
print(client.mirror_url)
# Create independent container sessions through this shared client.
For another discovery backend, pass an async function returning an absolute
HTTP(S) URL to GatewayDiscovery(discover). Explicit PodmanClient(gateway_url)
continues to work without discovery or the literegistry dependency.
Only an HTTP transport failure or request timeout invalidates the selection.
HTTP error responses, including worker capacity errors, do not. The failed
request is not retried: a command may already have executed. The next request
resolves the gateway again; a late failure from an older selection cannot clear
a newer one. Canceling one discovery waiter does not cancel the shared lookup.
Open the client before accessing mirror_url when no explicit URL was supplied.
Metadata
Release files for literegistry-podman-client 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| literegistry_podman_client-0.1.6.tar.gz | 20.1 kB | With provenance | Details for literegistry_podman_client-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| literegistry_podman_client-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for literegistry_podman_client-0.1.6-py3-none-any.whl |
Total release size: 34.0 kB
Release files / literegistry_podman_client-0.1.6.tar.gz
| Download URL | literegistry_podman_client-0.1.6.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5b764cacd1bdd9f035d6fdf8ab9253344255fc0631665f83d96c1749c6266e7
|
|
BLAKE2b-256 checksum How to use checksums |
7402ef991f4456f79611106a01e1f6c9b8156e8d8378d3cfba0deed92b25a735
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / literegistry_podman_client-0.1.6-py3-none-any.whl
| Download URL | literegistry_podman_client-0.1.6-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdb19f952439f8b84d7478e524f16fb4f9bd18a3658f4e295982faf2aa252d60
|
|
BLAKE2b-256 checksum How to use checksums |
b164c0378578a65dacbed935887e162b533d5d39ee8847786cbe23c0f7d44403
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for literegistry-podman-client 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for literegistry_podman_client-0.1.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.