No project description provided
Project description
CAC Core
An API client library providing essential functionality for command-line applications.
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
Installation
# Install from PyPI
pip install cac-core
# Or install with Poetry
poetry add 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)
Development
# Clone the repository
git clone https://github.com/rpunt/cac_core.git
cd cac_core
# Install dependencies
poetry install
# Run tests
poetry 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.3.2.tar.gz.
File metadata
- Download URL: cac_core-0.3.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb6e860112b115807c518c49187bf89e3e6a7031ab954dda9b24f79931128fd
|
|
| MD5 |
6b3a0f1f26d4aace40ed78c15b64cd86
|
|
| BLAKE2b-256 |
1db2100de33939b811ed59f4c94ff38d6e08460afe73f469c482d2a6d6001150
|
Provenance
The following attestation bundles were made for cac_core-0.3.2.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.3.2.tar.gz -
Subject digest:
ffb6e860112b115807c518c49187bf89e3e6a7031ab954dda9b24f79931128fd - Sigstore transparency entry: 202968227
- Sigstore integration time:
-
Permalink:
rpunt/cac-core@db726951b107267a1c21381a55753592529756eb -
Branch / Tag:
refs/tags/v0.3.2 - 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@db726951b107267a1c21381a55753592529756eb -
Trigger Event:
push
-
Statement type:
File details
Details for the file cac_core-0.3.2-py3-none-any.whl.
File metadata
- Download URL: cac_core-0.3.2-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97707c9f87061601850bd73bfb691460d5ce444f7e2bc7cae07b1c68d95fa586
|
|
| MD5 |
f8ed49feffd2b0aca3dddcd19ca3cc5c
|
|
| BLAKE2b-256 |
731743c0afc8919f3fd417146311b8cbd171ae855b3eb8558ae88cdb73cf05aa
|
Provenance
The following attestation bundles were made for cac_core-0.3.2-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.3.2-py3-none-any.whl -
Subject digest:
97707c9f87061601850bd73bfb691460d5ce444f7e2bc7cae07b1c68d95fa586 - Sigstore transparency entry: 202968232
- Sigstore integration time:
-
Permalink:
rpunt/cac-core@db726951b107267a1c21381a55753592529756eb -
Branch / Tag:
refs/tags/v0.3.2 - 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@db726951b107267a1c21381a55753592529756eb -
Trigger Event:
push
-
Statement type: