Skip to main content

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

  1. Build the libcc shared library:

    cd /path/to/cc
    ./tools/build.go -bindings-c
    
  2. Set the library path (or copy libcc.dylib/libcc.so to a standard location):

    export LIBCC_PATH=/path/to/cc/build/libcc.dylib
    
  3. 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 resources
  • cc.api_version() - Get API version string
  • cc.api_version_compatible(major, minor) - Check version compatibility
  • cc.supports_hypervisor() - Check if hypervisor is available
  • cc.query_capabilities() - Get system capabilities
  • cc.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 configuration
  • Capabilities - System capabilities
  • SeekWhence - 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 freed
  • InvalidArgumentError - Invalid function argument
  • NotRunningError - Instance has terminated
  • AlreadyClosedError - Resource already closed
  • TimeoutError - Operation timed out
  • HypervisorUnavailableError - No hypervisor support
  • IOError - Filesystem I/O error
  • NetworkError - Network error
  • CancelledError - 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

Metadata

Release files for crumblecracker 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for crumblecracker 0.0.3
File Interpreter ABI Platform
crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ ARM64 Details
crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 45.0 MB

Release files / crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl

Download URL crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_x86_64.whl
Size 17.0 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7095c080a770bcc145b2bd950b2db394b6c73ec14e108d9ce3c295167dd0f8f9
BLAKE2b-256 checksum
How to use checksums
5990260797ee88da9b7fe19151c305ded5917cb1eef31a21578c8e038efe728f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 13, 2026.

Transparency log

Release files / crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl

Download URL crumblecracker-0.0.3-cp312-cp312-manylinux_2_17_aarch64.whl
Size 15.6 MB
Tags CPython 3.12 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
c763c686208c1ecca2d835a998c6b03feca1ab7eb1ed739664dcefdecf4d77e5
BLAKE2b-256 checksum
How to use checksums
e17b27fedb99875ffe032729e249f996a4190fa391f38176b74ef29a7b1404ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 13, 2026.

Transparency log

Release files / crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL crumblecracker-0.0.3-cp312-cp312-macosx_11_0_arm64.whl
Size 12.4 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5e4b3c5d6e9e71669b1a8af27901feed950227f8878b0095e3582a9111cbb48d
BLAKE2b-256 checksum
How to use checksums
cfc0c14895d340f5df0b2fa3449f366f2c6ebf76f7b11f529d67f34fb1b87db2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.3 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page