Python Common Client Library - A collection of useful utilities for command-line applications
Project description
clicommon
A lightweight Python library providing common utilities for command-line applications. It simplifies logging, variable checking, and subprocess execution in CLI tools and scripts.
Features
bcheck: Check if a variable exists in the caller's scope and is truthymlog: Flexible logging with colored output, timestamps, and exit codesrcmd: Simple wrapper for running shell commands with error handling
Installation
pip install clicommon
Or using uv:
uv add clicommon
Usage
bcheck
Checks if a variable exists in the caller's scope and evaluates to True.
from clicommon import bcheck
my_var = True
if bcheck("my_var"):
print("Variable exists and is truthy")
if not bcheck("undefined_var"):
print("Variable does not exist or is falsy")
mlog
A versatile logging function with support for colors, timestamps, and exit codes.
from clicommon import mlog
# Simple message
mlog("INFO", "Starting process")
# Use colors (COLORS must be set in scope)
COLORS = True
mlog("SUCCESS", "Operation completed successfully")
# Add timestamps (DATELOG must be set in scope)
DATELOG = True
mlog("WARN", "This is a warning")
# Enable debug output (DEBUG must be set in scope)
DEBUG = True
mlog("DEBUG", "Debug information")
# Exit with code
mlog("ERROR", "Fatal error occurred", exit_code=1)
Message Types and Default Colors
| Type | Color |
|---|---|
| INFO | Green |
| SUCCESS | Green |
| WARN/WARNING | Yellow |
| FATAL/ERROR/CRITICAL | Red |
| TEST | Gray |
| DEBUG | Magenta |
| VERBOSE | Bright Cyan |
| BUILD_DEBUG/CODE_DEBUG | Bright Green |
Function Signature
def mlog(msg_type, msg_string=None, exit_code=None, datelog=None, colors=None)
msg_type: Type of message (determines color and verbosity filtering)msg_string: Message content (if None, msg_type becomes the message)exit_code: If provided, exit with this code after loggingdatelog: If True, add ISO8601 timestamp (or setDATELOG=Truein scope)colors: If True, use ANSI colors (or setCOLORS=Truein scope)
rcmd
Run shell commands with automatic error handling and logging.
from clicommon import rcmd
# Simple command execution
output = rcmd("ls -la")
print(output)
# Commands that fail will automatically log an error and exit
Development
Install development dependencies:
uv sync --dev
Run tests:
uv run pytest
Build the package:
uv build
Publishing to PyPI
To publish a new release to PyPI:
- Update the version in
pyproject.toml - Commit your changes
- Create and push a version tag:
git tag v0.3.0 git push origin v0.3.0
- The GitHub workflow will automatically:
- Run all tests
- Build the package
- Publish to PyPI (requires
PYPI_API_TOKENsecret in GitHub)
Important: Before tagging, ensure you have added a PYPI_API_TOKEN secret to your GitHub repository settings.
To test the build locally:
uv build
License
Apache License 2.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
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 clicommon-0.3.4.tar.gz.
File metadata
- Download URL: clicommon-0.3.4.tar.gz
- Upload date:
- Size: 66.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8f5609c05d4bfeff88e4145534e239729b070e3918d05784f10e2da217fdbd2
|
|
| MD5 |
019cf04456e47b40d3d4622263a23c5e
|
|
| BLAKE2b-256 |
108055e55c305164e0fa9e91ad551eed2b79d81c587e7d9c683402f29616e788
|
File details
Details for the file clicommon-0.3.4-py3-none-any.whl.
File metadata
- Download URL: clicommon-0.3.4-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc5413331763e5ee5bbf69acdcc67fef3fa0c5901df57fef912cf8294152a626
|
|
| MD5 |
464ca3f1ad51df0e38179b981cdb8ba2
|
|
| BLAKE2b-256 |
bb179ac85f9ddd5cbbc32a076a9e9dcf4bd18a63b4b3e2c14380f9c3f19b265f
|