Python ConTree SDK¶
ConTree is a container runtime, providing reproducible, versioned filesystem state — like Git for container execution. The SDK makes this accessible from Python.
Quick Start¶
Installation¶
Install the SDK from PyPi:
pip install contree-sdk
Basic Usage¶
1image = client.images.use("busybox:latest")
2print(f"Using {image=}")
3
4result = await image.run(shell="echo 'Hello World'")
5print(f"Simple echo: {result.stdout=}, {result.stderr=}, {result.exit_code=}")
6
7result = await image.run(shell="pwd")
8print(f"Current directory: {result.stdout=}, {result.exit_code=}")
9
10result = await image.run(shell="ls -la")
11print(f"Directory listing: {result.stdout=}, {result.exit_code=}")
12
13result = await image.run(shell="cat -", stdin="Hello from stdin\n")
14print(f"Cat with stdin: {result.stdout=}, {result.exit_code=}")
15
16result = await image.run(shell="echo 'Error message' >&2; exit 1")
17print(f"Error command: {result.stdout=}, {result.stderr=}, {result.exit_code=}")
1image = client.images.use("busybox:latest")
2print(f"Using {image=}")
3
4result = image.run(shell="echo 'Hello World'").wait()
5print(f"Simple echo: {result.stdout=}, {result.stderr=}, {result.exit_code=}")
6
7result = image.run(shell="pwd").wait()
8print(f"Current directory: {result.stdout=}, {result.exit_code=}")
9
10result = image.run(shell="ls -la").wait()
11print(f"Directory listing: {result.stdout=}, {result.exit_code=}")
12
13result = image.run(shell="cat -", stdin="Hello from stdin\n").wait()
14print(f"Cat with stdin: {result.stdout=}, {result.exit_code=}")
15
16result = image.run(shell="echo 'Error message' >&2; exit 1").wait()
17print(f"Error command: {result.stdout=}, {result.stderr=}, {result.exit_code=}")
What’s Next?¶
Ready to explore more? Check out our guides:
Getting Started - Detailed setup and basic operations
Working with Images - Pull and import container images
Running Commands - Comprehensive guide to command execution
Branching Workflows - Create reproducible execution branches