Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cac_core-0.3.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cac_core-0.3.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file cac_core-0.3.0.tar.gz.

File metadata

  • Download URL: cac_core-0.3.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cac_core-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aba4029db3340a845147ae567a83ae0dad9a9caedeb1e010084886df3a701136
MD5 a51e7c345b50b80e01a106c40bef7872
BLAKE2b-256 5e4cb21e3ccbf4523106d1dc1fe0958fb9b2c5e871b9c4992c6e3b7bf22dae2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cac_core-0.3.0.tar.gz:

Publisher: create_artifacts_and_publish.yaml on rpunt/cac-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cac_core-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cac_core-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cac_core-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f735608957d55d167e156fe1142e7f59622c317f089bf24e7a4f3d642bc4aa09
MD5 c517048b56c04f08d67338d4ce6c33ea
BLAKE2b-256 ab5657cabba27eec2cdbe35f17e90b51774bd7c80d21b30c064e11a0172c1a82

See more details on using hashes here.

Provenance

The following attestation bundles were made for cac_core-0.3.0-py3-none-any.whl:

Publisher: create_artifacts_and_publish.yaml on rpunt/cac-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page