Standardize your daily DevOps scripts with a clean, unified API.
Built for professionals who need reliability, structured logging, and zero-boilerplate.
- 🛡️ Robust Runner: Execute shell commands with built-in retries, timeouts, and safe result handling.
- ⚙️ Environment Manager: Strict validation, type casting (int, bool, float), and precedence handling (System > .env > Default).
- 💓 Health Checks: One-line checks for HTTP endpoints, TCP ports, and system processes.
- 📝 Unified Logger: Professional JSON/Text logging out-of-the-box, ready for Splunk/Datadog.
- 📐 Type Safe: 100% typed code base compatible with MyPy and VSCode Pylance.
pip install pykit-devExecute commands confidently with retry logic and detailed results.
from pykit_dev.runner import run, CommandExecutionError
try:
# Run with automatic retries and timeout
result = run("curl https://api.example.com", retry=2, timeout=5)
print(f"Status: {result.exit_code}")
print(f"Output: {result.stdout}")
except CommandExecutionError as e:
print(f"Failed after retries: {e}")Forget manual os.getenv casting and checking.
from pykit_dev.env import env
# Load from .env file (optional)
env.load(".env")
# Type-safe retrieval
db_url = env.require("DATABASE_URL") # Raises error if missing
debug = env.get("DEBUG", default=False, cast=bool) # Returns True/False, not "true"
max_conn = env.get("MAX_CONN", default=10, cast=int)Verify dependencies before starting your application.
from pykit_dev.health import health, HealthCheckFailed
try:
health.http("https://api.github.com")
health.tcp("localhost", 5432)
health.process(1234) # Check by PID
print("✅ System Healthy")
except HealthCheckFailed as e:
print(f"❌ Health Check Failed: {e}")from pykit_dev.core.logger import logger
logger.info("Deployment started", {"env": "production"})
# Output: {"timestamp": "...", "level": "INFO", "message": "Deployment started", "extra": {"env": "production"}}from pykit_dev.utils import start_timer, slugify
timer = start_timer()
# ... task ...
print(f"Elapsed: {timer.stop()}s")Contributions are welcome! Please ensure all code passes mypy and pytest.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.