zlayer
Python bindings for ZLayer — a lightweight, Rust-based container orchestration platform with built-in networking, scaling, and observability. ZLayer uses libcontainer (from youki) for direct container management without requiring a daemon.
This package ships prebuilt abi3 wheels (one wheel per OS/arch works on
CPython 3.8+), so pip install zlayer does not require a Rust toolchain.
Installation
From PyPI
pip install zlayer
From Source
# Requires Rust toolchain and maturin
pip install maturin
cd crates/zlayer-py
maturin develop
Quickstart: driving a remote daemon from Python
The zlayer.Client class talks to a running zlayer daemon over its Unix
socket — the same socket the zlayer CLI uses. zlayer.ensure_daemon()
bootstraps the zlayer binary if it isn't on PATH yet (downloaded into
~/.local/share/zlayer/bin/).
import asyncio
import zlayer
async def main():
# Make sure a `zlayer` binary is installed and the daemon is running.
# Returns the path to the binary. Use system=True to install system-wide
# via `sudo zlayer daemon install`.
zlayer.ensure_daemon()
# Connect to the local daemon (defaults to the standard Unix socket).
client = zlayer.Client()
# Deploy a spec and list running containers.
await client.deploy("deployment.yaml")
for container in await client.ps():
print(container)
asyncio.run(main())
Embedded runtime and builder
For in-process orchestration (no daemon required), ZLayer exposes a full
Runtime and ImageBuilder API:
import asyncio
from zlayer import Runtime, Container, ImageBuilder
async def main():
# Deploy from a spec file
runtime = Runtime()
await runtime.deploy_spec("deployment.yaml")
# Scale a service
await runtime.scale("my-deployment", "api", 3)
# Check status
status = await runtime.status()
print(status)
asyncio.run(main())
Quick Container Run
The easiest way to run a container is using the run() function:
import asyncio
import zlayer
async def main():
# Run nginx with port mapping
container = await zlayer.run("nginx:latest", ports={80: 8080})
print(f"Started: {container.id}")
# Run redis with a custom name
container = await zlayer.run("redis:alpine", name="my-redis")
# Run a one-shot command (waits for completion)
container = await zlayer.run(
"python:3.12",
command=["python", "-c", "print('hello')"],
detach=False
)
# Run with environment variables
container = await zlayer.run(
"postgres:16",
ports={5432: 5432},
env={"POSTGRES_PASSWORD": "secret"}
)
# Stop and clean up
await container.stop()
await container.remove()
asyncio.run(main())
Working with Containers
import asyncio
from zlayer import Container
async def main():
# Create a container from an image
container = Container.create(
"nginx:latest",
ports={"http": 80},
env={"NGINX_HOST": "localhost"}
)
# Start the container
await container.start()
# Wait for it to be healthy
await container.wait_healthy(timeout=30)
# Get logs
logs = await container.logs(tail=50)
print(logs)
# Stop and remove
await container.stop()
await container.remove()
asyncio.run(main())
Building Images
Quick Build (Convenience Function)
The simplest way to build an image is using the build() function:
import asyncio
import zlayer
async def main():
# Simple build
image = await zlayer.build("./app", tag="myapp:latest")
print(f"Built: {image}")
# Build with custom Dockerfile
image = await zlayer.build(".", tag="api:v1", dockerfile="Dockerfile.prod")
# Build with arguments
image = await zlayer.build(
"./app",
tag="myapp:latest",
build_args={"VERSION": "1.0.0", "DEBUG": "false"}
)
# Build without cache
image = await zlayer.build("./app", tag="myapp:latest", no_cache=True)
asyncio.run(main())
ImageBuilder (Full Control)
For more control over the build process, use the ImageBuilder class:
import asyncio
from zlayer import ImageBuilder, detect_runtime
async def main():
# Auto-detect runtime from project files
detected = detect_runtime("./my-app")
if detected:
print(f"Detected: {detected.name}")
# Build an image
builder = ImageBuilder("./my-app")
builder.tag("myapp:latest")
builder.tag("myapp:v1.0.0")
# Optionally use a runtime template
builder.runtime("node20")
# Build
image = await builder.build()
print(f"Built: {image.id}")
asyncio.run(main())
Working with Specs
from zlayer import Spec, validate_spec
# Validate a spec
yaml_content = """
version: v1
deployment: my-app
services:
api:
rtype: service
image:
name: myapp:latest
endpoints:
- name: http
protocol: http
port: 8080
"""
# Validate
is_valid = validate_spec(yaml_content)
print(f"Valid: {is_valid}")
# Parse
spec = Spec.from_yaml(yaml_content)
print(f"Deployment: {spec.deployment}")
print(f"Services: {spec.services}")
# Access service details
api = spec.get_service("api")
if api:
print(f"Image: {api.image}")
print(f"Endpoints: {api.endpoints}")
API Reference
Container
Container.create(image, ports=None, env=None, name=None)- Create a new containercontainer.start()- Start the containercontainer.stop(timeout=30)- Stop the containercontainer.remove()- Remove the containercontainer.logs(tail=100)- Get container logscontainer.wait_healthy(timeout=60)- Wait for healthy statuscontainer.exec(command)- Execute a command in the containercontainer.id- Container IDcontainer.status- Current status string
Runtime
Runtime(options=None)- Create a new runtimeRuntime.create(options=None)- Create a runtime asynchronouslyruntime.deploy_spec(path)- Deploy from a YAML fileruntime.deploy_yaml(yaml)- Deploy from a YAML stringruntime.scale(deployment, service, replicas)- Scale a serviceruntime.status(deployment=None)- Get statusruntime.list_services()- List all servicesruntime.get_container(service, replica=1)- Get a containerruntime.remove_service(service)- Remove a serviceruntime.shutdown()- Shutdown the runtime
ImageBuilder
ImageBuilder(context, dockerfile=None)- Create a new builderbuilder.tag(tag)- Add a tagbuilder.tags(tags)- Add multiple tagsbuilder.arg(name, value)- Set a build argumentbuilder.args(args)- Set multiple build argumentsbuilder.target(stage)- Set target stagebuilder.runtime(name)- Use a runtime templatebuilder.no_cache()- Disable cachingbuilder.auth(registry, username, password)- Set registry authbuilder.build()- Build the imagebuilder.push(tag=None)- Push to registry
Spec
Spec.from_yaml(yaml)- Parse from YAML stringSpec.from_file(path)- Parse from filespec.version- Spec versionspec.deployment- Deployment namespec.services- List of service namesspec.get_service(name)- Get a service specspec.to_yaml()- Convert to YAMLspec.to_dict()- Convert to dict
Helper Functions
run(image, name=None, ports=None, env=None, command=None, detach=True)- Run a container quicklybuild(path, tag, dockerfile=None, build_args=None, no_cache=False, progress=True)- Build an image (convenience function)parse_spec(yaml)- Parse a YAML spec to dictvalidate_spec(yaml)- Validate a YAML specdetect_runtime(path)- Detect runtime from projectlist_runtimes()- List available runtimesis_buildah_available()- Check if buildah is installedbuildah_install_instructions()- Get install instructionscreate_service_spec(name, image, port=None)- Create a service spec
Requirements
- Python 3.8+
- For image building: buildah installed on the system
- For container runtime: youki or similar OCI runtime
License
Apache-2.0
Metadata
Release files for zlayer 0.14.3
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 | |
|---|---|---|---|---|
| zlayer-0.14.3.tar.gz | 3.7 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zlayer-0.14.3-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
Total release size: 19.5 MB
Release files / zlayer-0.14.3.tar.gz
| Download URL | zlayer-0.14.3.tar.gz |
|---|---|
| Size | 3.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd4db8cf4f49f551406f7b2eb56fb0405c557db9ea5ef7d7110da5176360715f
|
|
BLAKE2b-256 checksum How to use checksums |
539b77aed1cbf30001a706b066b9a183b445d077248b200b47b0f4d098eda2c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / zlayer-0.14.3-cp38-abi3-win_amd64.whl
| Download URL | zlayer-0.14.3-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 15.8 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8a7bc8e7890dfe8e217ab4ac6a26e019d3a720eb3f2300a91632161d5971eaa0
|
|
BLAKE2b-256 checksum How to use checksums |
82ccb6414c68dbcc9917bcf38950e6fc27550e73bb077059e1842a0307c03a55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for zlayer 0.14.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.