Python bindings for the CrumbleCracker virtualization library
Project description
CrumbleCracker Python Bindings
Python bindings for the CrumbleCracker virtualization library, providing a Pythonic interface to cc's virtualization primitives.
Installation
From PyPI (Recommended)
pip install crumblecracker
The PyPI package includes the native library (libcc.so/libcc.dylib) for supported platforms.
From Source
-
Build the
libccshared library:cd /path/to/cc ./tools/build.go -bindings-c
-
Set the library path (or copy
libcc.dylib/libcc.soto a standard location):export LIBCC_PATH=/path/to/cc/build/libcc.dylib
-
Install the package:
pip install -e /path/to/cc/bindings/python
Quick Start
import crumblecracker as cc
# Initialize the library
cc.init()
# Check for hypervisor support
if cc.supports_hypervisor():
print("Hypervisor available!")
else:
print("No hypervisor - some features may be limited")
# Query system capabilities
caps = cc.query_capabilities()
print(f"Architecture: {caps.architecture}")
# Pull an image and create an instance
with cc.OCIClient() as client:
# Pull with progress callback
def on_progress(p):
if p.total > 0:
pct = p.current * 100 // p.total
print(f"\rDownloading: {pct}%", end="")
source = client.pull("alpine:latest", progress_callback=on_progress)
print() # newline after progress
# Get image config
config = source.get_config()
print(f"Image architecture: {config.architecture}")
# Create and run instance
options = cc.InstanceOptions(memory_mb=512, cpus=2)
with cc.Instance(source, options) as inst:
print(f"Instance ID: {inst.id}")
# Run a command
output = inst.command("echo", "Hello from VM!").output()
print(output.decode())
# File operations
inst.write_file("/tmp/test.txt", b"Hello, World!")
data = inst.read_file("/tmp/test.txt")
print(f"Read: {data.decode()}")
# Directory operations
inst.mkdir("/tmp/mydir")
for entry in inst.read_dir("/tmp"):
print(f" {entry.name} (dir={entry.is_dir})")
# Cleanup
cc.shutdown()
API Reference
Module Functions
cc.init()- Initialize the library (required before any other call)cc.shutdown()- Shutdown and release resourcescc.api_version()- Get API version stringcc.api_version_compatible(major, minor)- Check version compatibilitycc.supports_hypervisor()- Check if hypervisor is availablecc.query_capabilities()- Get system capabilitiescc.guest_protocol_version()- Get guest protocol version
Classes
OCIClient
OCI image client for pulling and managing container images.
with cc.OCIClient(cache_dir=None) as client:
source = client.pull("alpine:latest", options=None, progress_callback=None)
source = client.load_tar("/path/to/image.tar")
source = client.load_dir("/path/to/extracted")
client.export_dir(source, "/path/to/output")
Instance
A running VM instance with filesystem, command, and network access.
with cc.Instance(source, options) as inst:
# Properties
inst.id # Instance ID
inst.is_running # Check if running
# Lifecycle
inst.wait() # Wait for termination
inst.close() # Close and cleanup
# Filesystem
inst.read_file(path)
inst.write_file(path, data, mode=0o644)
inst.stat(path)
inst.mkdir(path, mode=0o755)
inst.remove(path)
inst.read_dir(path)
# File handles
with inst.open(path) as f:
data = f.read()
with inst.create(path) as f:
f.write(data)
# Commands
output = inst.command("echo", "hello").output()
exit_code = inst.command("ls", "-la").run()
# Networking
listener = inst.listen("tcp", ":8080")
# Snapshots
snapshot = inst.snapshot_filesystem()
Cmd
Command builder for execution in instances.
cmd = inst.command("env")
cmd.set_dir("/tmp")
cmd.set_env("MY_VAR", "value")
# Synchronous execution
exit_code = cmd.run()
# Capture output
stdout = cmd.output()
combined = cmd.combined_output()
# Async execution
cmd.start()
# ... do other work ...
exit_code = cmd.wait()
# Streaming I/O with pipes
cmd = inst.command("cat")
stdin = cmd.stdin_pipe() # Returns Conn (writable)
stdout = cmd.stdout_pipe() # Returns Conn (readable)
stderr = cmd.stderr_pipe() # Returns Conn (readable)
cmd.start()
stdin.write(b"hello")
stdin.close() # Close to signal EOF
data = stdout.read(256) # Read output incrementally
stdout.close()
cmd.wait()
File
File handle for read/write operations.
with inst.open(path) as f:
data = f.read()
data = f.read(1024) # Read up to 1024 bytes
f.seek(0, cc.SeekWhence.SET)
info = f.stat()
with inst.create(path) as f:
f.write(b"data")
f.truncate(10)
f.sync()
Types
InstanceOptions- VM configuration (memory_mb, cpus, timeout_seconds, user, mounts)PullOptions- Image pull options (platform, auth, policy)PullPolicy- Pull policy enum (IF_NOT_PRESENT, ALWAYS, NEVER)FileInfo- File metadata (name, size, mode, is_dir, is_symlink)DirEntry- Directory entry (name, is_dir, mode)ImageConfig- OCI image configurationCapabilities- System capabilitiesSeekWhence- Seek origin (SET, CUR, END)
File Open Flags
cc.O_RDONLY # Read only
cc.O_WRONLY # Write only
cc.O_RDWR # Read and write
cc.O_APPEND # Append mode
cc.O_CREATE # Create if not exists
cc.O_TRUNC # Truncate to zero
cc.O_EXCL # Exclusive create
Exceptions
All exceptions inherit from cc.CCError:
InvalidHandleError- Handle is invalid or freedInvalidArgumentError- Invalid function argumentNotRunningError- Instance has terminatedAlreadyClosedError- Resource already closedTimeoutError- Operation timed outHypervisorUnavailableError- No hypervisor supportIOError- Filesystem I/O errorNetworkError- Network errorCancelledError- Operation was cancelled
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run tests (non-VM tests only)
pytest
# Run all tests including VM tests (requires hypervisor)
CC_RUN_VM_TESTS=1 pytest
License
MIT
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 Distributions
Built Distributions
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 crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 17.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7095c080a770bcc145b2bd950b2db394b6c73ec14e108d9ce3c295167dd0f8f9
|
|
| MD5 |
c5748cd1d7dd0d8c4c42bd7f2f271ae1
|
|
| BLAKE2b-256 |
5990260797ee88da9b7fe19151c305ded5917cb1eef31a21578c8e038efe728f
|
Provenance
The following attestation bundles were made for crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl:
Publisher:
release-bindings.yml on tinyrange/cc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl -
Subject digest:
7095c080a770bcc145b2bd950b2db394b6c73ec14e108d9ce3c295167dd0f8f9 - Sigstore transparency entry: 947200145
- Sigstore integration time:
-
Permalink:
tinyrange/cc@b648768e2e2ab934375508aa9906875d555a3ac8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tinyrange
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-bindings.yml@b648768e2e2ab934375508aa9906875d555a3ac8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl.
File metadata
- Download URL: crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl
- Upload date:
- Size: 15.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c763c686208c1ecca2d835a998c6b03feca1ab7eb1ed739664dcefdecf4d77e5
|
|
| MD5 |
e2c3a3a79571eeece9b46c7dcc9fdb6f
|
|
| BLAKE2b-256 |
e17b27fedb99875ffe032729e249f996a4190fa391f38176b74ef29a7b1404ed
|
Provenance
The following attestation bundles were made for crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl:
Publisher:
release-bindings.yml on tinyrange/cc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl -
Subject digest:
c763c686208c1ecca2d835a998c6b03feca1ab7eb1ed739664dcefdecf4d77e5 - Sigstore transparency entry: 947200137
- Sigstore integration time:
-
Permalink:
tinyrange/cc@b648768e2e2ab934375508aa9906875d555a3ac8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tinyrange
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-bindings.yml@b648768e2e2ab934375508aa9906875d555a3ac8 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 12.4 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e4b3c5d6e9e71669b1a8af27901feed950227f8878b0095e3582a9111cbb48d
|
|
| MD5 |
7683f2e77608ddda94f6b02853d9cb35
|
|
| BLAKE2b-256 |
cfc0c14895d340f5df0b2fa3449f366f2c6ebf76f7b11f529d67f34fb1b87db2
|
Provenance
The following attestation bundles were made for crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
release-bindings.yml on tinyrange/cc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
5e4b3c5d6e9e71669b1a8af27901feed950227f8878b0095e3582a9111cbb48d - Sigstore transparency entry: 947200142
- Sigstore integration time:
-
Permalink:
tinyrange/cc@b648768e2e2ab934375508aa9906875d555a3ac8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tinyrange
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-bindings.yml@b648768e2e2ab934375508aa9906875d555a3ac8 -
Trigger Event:
workflow_dispatch
-
Statement type: