# CAC Core
An API client library providing essential functionality for command-line applications.
This project uses [UV](https://github.com/astral-sh/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
```bash
pip install cac-core
```
## Usage
### Command
```python
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
```python
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
```python
import cac_core as cac
# Create a logger
logger = cac.logger.new(__name__)
logger.info("Application started")
logger.debug("Debug information")
```
### Data Models
```python
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
```python
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
```python
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
```bash
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "cac-core",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "api, framework, cli, command-lint, python, cli-tool",
"author": null,
"author_email": "Ryan Punt <ryan@mirum.org>",
"download_url": "https://files.pythonhosted.org/packages/34/28/87fd535b04a8bd2ba24a209a1cc39227dc435ce57ad03499f38f29223c49/cac_core-0.5.2.tar.gz",
"platform": null,
"description": "# CAC Core\n\nAn API client library providing essential functionality for command-line applications.\n\nThis project uses [UV](https://github.com/astral-sh/uv) for dependency management.\n\n## Overview\n\nCAC 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.\n\n## Features\n\n- **Command**: Define commands, required or optional arguments, and action implementations\n- **Configuration Management**: Load/save configs from YAML files with environment variable support\n- **Standardized Logging**: Consistent, configurable logging across applications\n- **Data Modeling**: Dynamic attribute creation and manipulation with dictionary-like access\n- **Output Formatting**: Display data as tables or JSON with customization options\n- **Update Checking**: Automatically check for package updates from PyPI or GitHub, with configurable intervals and notification options\n\n## Installation\n\n```bash\npip install cac-core\n```\n\n## Usage\n\n### Command\n\n```python\nimport cac_core as cac\n\n# Create a command class\nclass HelloCommand(cac.command.Command):\n def define_arguments(self, parser):\n \"\"\"Define command arguments\"\"\"\n parser.add_argument('--name', default='World',\n help='Name to greet')\n\n def execute(self, args):\n \"\"\"Execute the command with parsed arguments\"\"\"\n logger = cac.logger.new(__name__)\n logger.info(f\"Hello, {args.name}!\")\n return f\"Hello, {args.name}!\"\n\n# Use the command in your application\nif __name__ == \"__main__\":\n # Create argument parser\n import argparse\n parser = argparse.ArgumentParser(description='Demo application')\n\n # Initialize command\n cmd = HelloCommand()\n\n # Add command arguments\n cmd.define_arguments(parser)\n\n # Parse arguments\n args = parser.parse_args()\n\n # Execute command\n result = cmd.execute(args)\n\n # Display result\n print(result)\n```\n\n### Configuration\n\n```python\nimport cac_core as cac\n\n# Load configuration\nconfig = cac.config.Config(\"myapp\")\nserver_url = config.get(\"server\", \"default-value\")\n\n# Update configuration\nconfig.set(\"api_key\", \"my-secret-key\")\nconfig.save()\n```\n\n### Logging\n\n```python\nimport cac_core as cac\n\n# Create a logger\nlogger = cac.logger.new(__name__)\nlogger.info(\"Application started\")\nlogger.debug(\"Debug information\")\n```\n\n### Data Models\n\n```python\nimport cac_core as cac\n\n# Create data model\ndata = {\n \"name\": \"Project X\",\n \"status\": \"active\",\n \"metadata\": {\n \"created\": \"2025-01-01\",\n \"version\": \"1.0\"\n }\n}\n\nmodel = cac.model.Model(data)\nprint(model.name) # \"Project X\"\nprint(model.metadata.version) # \"1.0\"\n```\n\n### Output Formatting\n\n```python\nimport cac_core as cac\n\n# Create output handler\noutput = cac.output.Output({\"output\": \"table\"})\n\n# Display data as table\nmodels = [model1, model2, model3]\noutput.print_models(models)\n\n# Display as JSON\noutput = cac.output.Output({\"output\": \"json\"})\noutput.print_models(models)\n```\n\n### Update Checking\n\n```python\nimport cac_core as cac\n\n# Check for updates to your package (using PyPI by default)\nchecker = cac.updatechecker.UpdateChecker(\"your-package-name\")\nstatus = checker.check_for_updates()\n\n# Notify users if an update is available\nif status[\"update_available\"]:\n print(f\"Update available: {status['current_version']} \u2192 {status['latest_version']}\")\n\n# Convenience function for quick checks\ncac.updatechecker.check_package_for_updates(\"your-package-name\", notify=True)\n\n# Configure source options\n# PyPI (default)\npypi_checker = cac.updatechecker.UpdateChecker(\n \"your-package-name\",\n source=\"pypi\" # This is the default, so it's optional\n)\n\n# GitHub\ngithub_checker = cac.updatechecker.UpdateChecker(\n \"your-package-name\",\n source=\"github\",\n repo=\"username/repo-name\"\n)\n\n# Add update checking to your CLI application\ndef main():\n # Check for updates once per day\n from datetime import timedelta\n checker = cac.updatechecker.UpdateChecker(\n \"your-package-name\",\n check_interval=timedelta(days=1)\n )\n\n # Only notify if update is available, otherwise be quiet\n checker.check_for_updates()\n checker.notify_if_update_available(quiet=True)\n\n # Rest of your application...\n```\n\n## Development\n\n```bash\npip install uv\n\n# Clone the repository\ngit clone https://github.com/rpunt/cac_core.git\ncd cac_core\nuv venv\nuv pip install -e .\n\n# Install dependencies\nuv pip install -e \".[dev]\"\nuv pip install -e \".[test]\"\nuv pip install -e \".[lint]\"\n\n# Run tests\nuv run pytest\n```\n\n## Project Structure\n\n- command.py - Command management\n- config.py - Configuration management\n- logger.py - Standardized logging\n- model.py - Data modeling utilities\n- output.py - Output formatting\n\n## License\n\nMIT\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.5.2",
"project_urls": {
"homepage": "https://mirum.org/cac-core/",
"repository": "https://github.com/rpunt/cac-core"
},
"split_keywords": [
"api",
" framework",
" cli",
" command-lint",
" python",
" cli-tool"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "08719443d328472e487d3af72e8a6dbd14b0170eea7aa8ef6103f7ab635a543b",
"md5": "7dc3072093f18a0855a966316af84510",
"sha256": "0abf5446cd411bd345f55d178702a0287f823e22343dcfa4d1641b01f78e9429"
},
"downloads": -1,
"filename": "cac_core-0.5.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7dc3072093f18a0855a966316af84510",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 21745,
"upload_time": "2025-08-06T22:13:35",
"upload_time_iso_8601": "2025-08-06T22:13:35.641424Z",
"url": "https://files.pythonhosted.org/packages/08/71/9443d328472e487d3af72e8a6dbd14b0170eea7aa8ef6103f7ab635a543b/cac_core-0.5.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "342887fd535b04a8bd2ba24a209a1cc39227dc435ce57ad03499f38f29223c49",
"md5": "e22ae5c7b69bd2fe3ccf5f749b01aa42",
"sha256": "9c8e88eae4b80072ab9792332ca3f3117e084a22697cec5d4363ef9138e2efde"
},
"downloads": -1,
"filename": "cac_core-0.5.2.tar.gz",
"has_sig": false,
"md5_digest": "e22ae5c7b69bd2fe3ccf5f749b01aa42",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 20317,
"upload_time": "2025-08-06T22:13:38",
"upload_time_iso_8601": "2025-08-06T22:13:38.083713Z",
"url": "https://files.pythonhosted.org/packages/34/28/87fd535b04a8bd2ba24a209a1cc39227dc435ce57ad03499f38f29223c49/cac_core-0.5.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-06 22:13:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rpunt",
"github_project": "cac-core",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cac-core"
}