No project description provided
Project description
CAC Core
An API client library providing essential functionality for command-line applications.
This project uses UV for dependency management.
Overview
CAC Core (cac-core) is a Python library that provides common utilities for building robust command-line applications. It includes modules for commands, configuration management, standardized logging, data modeling, and formatted output display.
Features
- Command: Define commands, required or optional arguments, and action implementations
- Configuration Management: Load/save configs from YAML files with environment variable support
- Standardized Logging: Consistent, configurable logging across applications
- Data Modeling: Dynamic attribute creation and manipulation with dictionary-like access
- Output Formatting: Display data as tables or JSON with customization options
- Update Checking: Automatically check for package updates from PyPI or GitHub, with configurable intervals and notification options
Installation
pip install cac-core
Usage
Command
import cac_core as cac
# Create a command class
class HelloCommand(cac.command.Command):
def define_arguments(self, parser):
"""Define command arguments"""
parser.add_argument('--name', default='World',
help='Name to greet')
def execute(self, args):
"""Execute the command with parsed arguments"""
logger = cac.logger.new(__name__)
logger.info(f"Hello, {args.name}!")
return f"Hello, {args.name}!"
# Use the command in your application
if __name__ == "__main__":
# Create argument parser
import argparse
parser = argparse.ArgumentParser(description='Demo application')
# Initialize command
cmd = HelloCommand()
# Add command arguments
cmd.define_arguments(parser)
# Parse arguments
args = parser.parse_args()
# Execute command
result = cmd.execute(args)
# Display result
print(result)
Configuration
import cac_core as cac
# Load configuration
config = cac.config.Config("myapp")
server_url = config.get("server", "default-value")
# Update configuration
config.set("api_key", "my-secret-key")
config.save()
Logging
import cac_core as cac
# Create a logger
logger = cac.logger.new(__name__)
logger.info("Application started")
logger.debug("Debug information")
Data Models
import cac_core as cac
# Create data model
data = {
"name": "Project X",
"status": "active",
"metadata": {
"created": "2025-01-01",
"version": "1.0"
}
}
model = cac.model.Model(data)
print(model.name) # "Project X"
print(model.metadata.version) # "1.0"
Output Formatting
import cac_core as cac
# Create output handler
output = cac.output.Output({"output": "table"})
# Display data as table
models = [model1, model2, model3]
output.print_models(models)
# Display as JSON
output = cac.output.Output({"output": "json"})
output.print_models(models)
Update Checking
import cac_core as cac
# Check for updates to your package (using PyPI by default)
checker = cac.updatechecker.UpdateChecker("your-package-name")
status = checker.check_for_updates()
# Notify users if an update is available
if status["update_available"]:
print(f"Update available: {status['current_version']} → {status['latest_version']}")
# Convenience function for quick checks
cac.updatechecker.check_package_for_updates("your-package-name", notify=True)
# Configure source options
# PyPI (default)
pypi_checker = cac.updatechecker.UpdateChecker(
"your-package-name",
source="pypi" # This is the default, so it's optional
)
# GitHub
github_checker = cac.updatechecker.UpdateChecker(
"your-package-name",
source="github",
repo="username/repo-name"
)
# Add update checking to your CLI application
def main():
# Check for updates once per day
from datetime import timedelta
checker = cac.updatechecker.UpdateChecker(
"your-package-name",
check_interval=timedelta(days=1)
)
# Only notify if update is available, otherwise be quiet
checker.check_for_updates()
checker.notify_if_update_available(quiet=True)
# Rest of your application...
Development
pip install uv
# Clone the repository
git clone https://github.com/rpunt/cac_core.git
cd cac_core
uv venv
uv pip install -e .
# Install dependencies
uv pip install -e ".[dev]"
uv pip install -e ".[test]"
uv pip install -e ".[lint]"
# Run tests
uv run pytest
Project Structure
- command.py - Command management
- config.py - Configuration management
- logger.py - Standardized logging
- model.py - Data modeling utilities
- output.py - Output formatting
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 cac_core-0.6.0.tar.gz.
File metadata
- Download URL: cac_core-0.6.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
205505382b4eba776e6eae43b22b862b5a272a05103fa3738026a5e891bd8b6a
|
|
| MD5 |
4b942fd6e4858fd786bad46d6364622e
|
|
| BLAKE2b-256 |
b863998ed7523e69dd080e969f387b7d647c7411718aa3a0014f06c3a49aa96f
|
Provenance
The following attestation bundles were made for cac_core-0.6.0.tar.gz:
Publisher:
create_artifacts_and_publish.yaml on rpunt/cac-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cac_core-0.6.0.tar.gz -
Subject digest:
205505382b4eba776e6eae43b22b862b5a272a05103fa3738026a5e891bd8b6a - Sigstore transparency entry: 974840888
- Sigstore integration time:
-
Permalink:
rpunt/cac-core@b0318f26fc86c09acd30cf26b3fa2e21348d7c48 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/rpunt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
create_artifacts_and_publish.yaml@b0318f26fc86c09acd30cf26b3fa2e21348d7c48 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cac_core-0.6.0-py3-none-any.whl.
File metadata
- Download URL: cac_core-0.6.0-py3-none-any.whl
- Upload date:
- Size: 21.8 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 |
17730b999c2a4b7fbbbd53ae919536259253fbd5b5513ba417a9407eb6819e9a
|
|
| MD5 |
0501ca62f1d39afd682dadfbd8e323f3
|
|
| BLAKE2b-256 |
7998317125fa41e16fa0f1a49b2ebfe7af2517f76002581e8dd97abbc78490b9
|
Provenance
The following attestation bundles were made for cac_core-0.6.0-py3-none-any.whl:
Publisher:
create_artifacts_and_publish.yaml on rpunt/cac-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cac_core-0.6.0-py3-none-any.whl -
Subject digest:
17730b999c2a4b7fbbbd53ae919536259253fbd5b5513ba417a9407eb6819e9a - Sigstore transparency entry: 974840912
- Sigstore integration time:
-
Permalink:
rpunt/cac-core@b0318f26fc86c09acd30cf26b3fa2e21348d7c48 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/rpunt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
create_artifacts_and_publish.yaml@b0318f26fc86c09acd30cf26b3fa2e21348d7c48 -
Trigger Event:
push
-
Statement type: