Python SDK for Apple Container with direct XPC
Project description
Apple Container Python SDK
A Python SDK for interacting with Apple Container via XPC communication. Provides a Docker-like API for container management on macOS.
Features
- Async/Await Support: Full async API using modern Python patterns
- XPC Communication: Direct communication with Apple Container daemon via XPC
- Docker-like API: Familiar interface for Docker users
- Type Safety: Full type hints and Pydantic models
- macOS Native: Built specifically for Apple Container on macOS
Installation
pip install apple-container
Requirements
- macOS 15.0+ (macOS Sequoia)
- Apple Silicon (M1/M2/M3/M4)
- Python 3.9+
- Apple Container daemon running
Quick Start
import asyncio
from apple_container import AppleContainerClient, ContainerConfig
async def main():
client = AppleContainerClient()
# Check if daemon is running
if await client.ping():
print("Apple Container daemon is running")
# List containers
containers = await client.list_containers()
print(f"Found {len(containers)} containers")
# Create and run a container
config = ContainerConfig(
id="", # Auto-generated
image="alpine:latest",
command=["echo", "Hello World"]
)
container = await client.create_container(config)
await client.start_container(container.id)
# Get logs
logs = await client.get_container_logs(container.id)
print(f"Container output: {logs.stdout}")
# Clean up
await client.stop_container(container.id)
await client.remove_container(container.id)
else:
print("Apple Container daemon is not running")
asyncio.run(main())
API Reference
Client
from apple_container import AppleContainerClient
client = AppleContainerClient(timeout=30.0)
Container Operations
# List containers
containers = await client.list_containers(all=False)
# Get container by ID/name
container = await client.get_container("container_id")
# Create container
config = ContainerConfig(id="", image="alpine:latest")
container = await client.create_container(config)
# Container lifecycle
await client.start_container("container_id")
await client.stop_container("container_id")
await client.restart_container("container_id")
await client.remove_container("container_id", force=False)
# Container info
logs = await client.get_container_logs("container_id", follow=False, tail=100)
stats = await client.get_container_stats("container_id")
Image Operations
# List images
images = await client.list_images()
# Get image by ID/name
image = await client.get_image("image_id")
# Pull image
image = await client.pull_image("alpine", tag="latest")
# Remove image
await client.remove_image("image_id", force=False)
Network Operations
# List networks
networks = await client.list_networks()
# Get network by ID/name
network = await client.get_network("network_id")
# Create network
config = NetworkConfig(id="", name="my-network")
network = await client.create_network(config)
# Remove network
await client.remove_network("network_id")
System Operations
# Check daemon status
is_running = await client.ping()
# Get version info
version = await client.version()
# Get system info
info = await client.system_info()
Convenience Functions
from apple_container import ping, list_containers, run_container
# Quick operations
is_running = await ping()
containers = await list_containers(all=True)
container = await run_container("alpine:latest", command=["echo", "hello"])
Error Handling
from apple_container import AppleContainerError, AppleContainerNotFoundError
try:
container = await client.get_container("nonexistent")
except AppleContainerNotFoundError:
print("Container not found")
except AppleContainerError as e:
print(f"Error: {e}")
Models
The SDK uses Pydantic models for type safety:
Container: Container information and stateContainerConfig: Configuration for creating containersContainerLogs: Container log outputContainerStats: Container resource usage statisticsImage: Image informationNetwork: Network informationNetworkConfig: Configuration for creating networks
Examples
See the examples/ directory for more comprehensive examples:
examples/basic_usage.py: Basic SDK usage demonstration
XPC Communication
This SDK communicates directly with the Apple Container daemon via XPC (Cross-Process Communication), providing:
- Native Integration: Direct communication with macOS services
- Security: Leverages macOS security model
- Performance: Efficient binary protocol
- Reliability: Built-in error handling and reconnection
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apple_container-0.0.1.tar.gz.
File metadata
- Download URL: apple_container-0.0.1.tar.gz
- Upload date:
- Size: 46.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75b76b3a5162f481fbe1e3501dbd48271710d373e2c639f0c478e4e288921af5
|
|
| MD5 |
7b3a66943f31066703b8951c2e41811c
|
|
| BLAKE2b-256 |
0f4c300800f5414a73a5ca8cbd0d3eb349d9f52653d47bb5fbb742e3157a66bf
|
File details
Details for the file apple_container-0.0.1-py3-none-any.whl.
File metadata
- Download URL: apple_container-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
359838c51627332868c3078c09db8c7321a734252eee96078b28bb090cdce776
|
|
| MD5 |
d02426e25cd82fb15d3d50a32454c3d3
|
|
| BLAKE2b-256 |
beaf5626d5aa766e60524dfe8faa1039cba63247c9bbcae0abeb81d31a365533
|