A Python framework for creating custom CLI tools using Podman
Project description
Rapidctl
Rapidctl is a Python framework for creating custom CLI tools that execute commands inside containerized environments using Podman. It allows you to package and distribute CLI utilities where all dependencies and runtime environments are containerized, ensuring consistency across different systems.
๐ฏ Purpose
Rapidctl solves the problem of distributing CLI tools with complex dependencies. Instead of requiring users to install specific versions of languages, libraries, or system packages, you package everything in a container and provide a lightweight Python wrapper that handles container orchestration transparently.
๐๏ธ Architecture
Rapidctl consists of three main layers:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Custom CLI (e.g. examplectl) โ โ User-facing entry point
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Bootstrap Layer (CtlClient) โ โ Configuration & validation
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ CLI Layer (PodmanCLI) โ โ Container orchestration
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Podman API โ โ Container runtime
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Components
-
Bootstrap Layer (
rapidctl.bootstrap.client)CtlClient: Defines container configuration and validates container image names- Prevents command injection through input sanitization
-
Connectors (
rapidctl.bootstrap.connectors)- Connectors are used to connect to the container runtime
- Connectors are platform specific
- Connectors are used by the CLI Layer to interact with the container runtime
- Connectors are plugins for different ecosystems (Window, OSX, Linux, etc)
-
CLI Layer (
rapidctl.cli)PodmanCLI: Interfaces with Podman API for container operations- Handles image pulling, container management, and command execution
-
Actions (
rapidctl.cli.actions)- Actions are an operation to achieve an outcome
- Actions orchestrate and use one or more tasks to achieve their outcome
-
Tasks (
rapidctl.cli.tasks)- Tasks perform a single operation
- Tasks are the building blocks of actions
๐ Quick Start
Prerequisites
- Python 3.10+
- Podman installed and running (on macOS, you will be automatically prompted to start the machine if it is stopped)
podmanPython package
Installation
# Clone the repository
git clone https://github.com/yourusername/rapidctl.git
cd rapidctl
# Install dependencies
pip install podman
# Optional: Set the Podman socket path manually (auto-detected by default)
# export PODMAN_SOCKET="unix:///run/user/$(id -u)/podman/podman.sock"
Creating Your Custom CLI Tool
- Create your CLI wrapper (e.g.,
myctl):
#!/usr/bin/env python
import re
import sys
from rapidctl.cli.main import main
from rapidctl.bootstrap import client
# Create and configure the client
client = client.CtlClient()
client.container_repo = "docker.io/myorg/mytool-container"
client.baseline_version = "1.0.0"
client.client_version = "0.0.1"
# Run the CLI
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main(client))
- Make it executable:
chmod +x myctl
- Use your CLI:
./myctl <command> <args>
The tool will automatically:
- Check if the container image exists locally
- Pull the image if needed
- Execute your command inside the container
๐ Example: rapidctl-examplectl
A complete reference implementation and template for building your own CLI tool can be found in the rapidctl-examplectl repository.
It includes:
- A working CLI wrapper
- A
Dockerfilefor the container environment - Example command orchestration scripts
- Version management demonstrations
๐ง Configuration
CtlClient Properties
| Property | Type | Default | Description |
|---|---|---|---|
container_repo |
str |
None |
Container registry path (e.g., docker.io/user/image) |
baseline_version |
str |
"1.0.0" |
Container image tag/version |
client_version |
str |
"0.0.1" |
Your CLI tool version |
image_id |
str |
None |
Specific image ID (optional) |
command_path |
str |
"/opt/rapidctl/cmd/" |
Path inside container where commands are located |
Environment Variables
PODMAN_SOCKET: Path to Podman socket (optional)- If not set, rapidctl will auto-detect the socket location using platform-specific connectors
- On macOS, auto-detection checks:
~/.local/share/containers/podman/machine/podman.sock/var/run/docker.sock- Machine-specific socket locations
- Override auto-detection by setting this variable:
export PODMAN_SOCKET="unix:///path/to/your/podman.sock"
- Useful for custom Podman installations or when running multiple Podman instances
๐ Security
Rapidctl includes container image name validation to prevent command injection attacks:
- Sanitizes registry URLs and image names
- Validates domain names and repository paths
- Removes dangerous characters (
;,|,&, etc.) - Supports standard Docker/Podman image formats
Example validated formats:
ubuntu:20.04docker.io/library/ubuntu:latestregistry.example.com/myproject/myimage:v1.2.3localhost:5000/my-image
๐งช Testing
Run the test suite:
# Run all tests
pytest tests/
# Run specific test
pytest tests/test_client.py
pytest tests/test_container_validator.py
๐ฆ Project Structure
rapidctl/
โโโ rapidctl/
โ โโโ __init__.py
โ โโโ bootstrap/
โ โ โโโ __init__.py
โ โ โโโ client.py # CtlClient configuration
โ โ โโโ state.py # State and cache management
โ โ โโโ connectors/
โ โ โโโ __init__.py
โ โ โโโ base.py # BaseConnector interface
โ โ โโโ linux.py
โ โ โโโ osx.py
โ โโโ cli/
โ โ โโโ __init__.py # PodmanCLI class
โ โ โโโ main.py # Main entry point
โ โ โโโ actions.py # High-level actions
โ โ โโโ mcp.py # MCP server integration
โ โ โโโ tasks.py # Low-level tasks
โ โโโ utils/
โ โ โโโ version.py # Version utilities
โ โโโ errors/
โ โโโ __init__.py # Custom exceptions
โโโ tests/
โ โโโ test_client.py
โ โโโ test_container_validator.py
โ โโโ ... (comprehensive test suite)
โโโ examples/
โ โโโ example_connector_usage.py
โโโ pyproject.toml # Packaging configuration
โโโ README.md
๐ ๏ธ Development Status
Current Status: Alpha / In Development
Known Limitations
- Limited error handling and recovery
Roadmap
- Complete command execution implementation
- Add comprehensive error handling
- Implement CLI argument parsing
- Implement MCP support
- Add logging framework
- Create packaging configuration (pyproject.toml)
- Expand test coverage
- Add CI/CD pipeline
- Platform-specific socket detection (macOS complete)
- Add Linux connector
- Add Windows connector
๐ค Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
๐ License
[Add your license here]
๐ Support
For questions or issues, please open an issue on GitHub.
Note: This project is under active development. APIs may change between versions.
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 rapidctl-0.1.1.tar.gz.
File metadata
- Download URL: rapidctl-0.1.1.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b20f9a0508653e56f1678ae0efceaacf820ea8579fdebca0249bdb6ed34d7c71
|
|
| MD5 |
113d53792e026fda487732974bce2974
|
|
| BLAKE2b-256 |
a22baa773eec45632abb8b5bd844dfc6b77f02278270f1dcae0b34183b46ff6e
|
Provenance
The following attestation bundles were made for rapidctl-0.1.1.tar.gz:
Publisher:
python-publish.yml on dalethestirling/rapidctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rapidctl-0.1.1.tar.gz -
Subject digest:
b20f9a0508653e56f1678ae0efceaacf820ea8579fdebca0249bdb6ed34d7c71 - Sigstore transparency entry: 1080872671
- Sigstore integration time:
-
Permalink:
dalethestirling/rapidctl@72cf5fea6483698fb4e9396abc182160c3521a71 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dalethestirling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@72cf5fea6483698fb4e9396abc182160c3521a71 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rapidctl-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rapidctl-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b0e93208b6d0489e3a1855c964bc3a792ea33d44773e300e8bca779998ccc53
|
|
| MD5 |
5258855df99148dcad4192d651afdeab
|
|
| BLAKE2b-256 |
f13201047890ecf799c3177ccc614970c6db7b49e219d2358fd133ba693a95da
|
Provenance
The following attestation bundles were made for rapidctl-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on dalethestirling/rapidctl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rapidctl-0.1.1-py3-none-any.whl -
Subject digest:
1b0e93208b6d0489e3a1855c964bc3a792ea33d44773e300e8bca779998ccc53 - Sigstore transparency entry: 1080872720
- Sigstore integration time:
-
Permalink:
dalethestirling/rapidctl@72cf5fea6483698fb4e9396abc182160c3521a71 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/dalethestirling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@72cf5fea6483698fb4e9396abc182160c3521a71 -
Trigger Event:
release
-
Statement type: