Skip to main content

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)
  • podman Python 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

  1. 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))
  1. Make it executable:
chmod +x myctl
  1. 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 Dockerfile for 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.04
  • docker.io/library/ubuntu:latest
  • registry.example.com/myproject/myimage:v1.2.3
  • localhost: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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rapidctl-0.1.1.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rapidctl-0.1.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

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

Hashes for rapidctl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b20f9a0508653e56f1678ae0efceaacf820ea8579fdebca0249bdb6ed34d7c71
MD5 113d53792e026fda487732974bce2974
BLAKE2b-256 a22baa773eec45632abb8b5bd844dfc6b77f02278270f1dcae0b34183b46ff6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidctl-0.1.1.tar.gz:

Publisher: python-publish.yml on dalethestirling/rapidctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rapidctl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b0e93208b6d0489e3a1855c964bc3a792ea33d44773e300e8bca779998ccc53
MD5 5258855df99148dcad4192d651afdeab
BLAKE2b-256 f13201047890ecf799c3177ccc614970c6db7b49e219d2358fd133ba693a95da

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidctl-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on dalethestirling/rapidctl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page