Skip to main content

ccfg

A Python library for managing hierarchical configurations using a class-based approach.

Features

  • Define configuration hierarchies using Python classes
  • Access configuration hierarchically using dot notation, enabling IDE autocompletion
  • Access to non-existent paths returns None instead of raising errors
  • Automatically convert between configuration classes and dictionaries
  • Support for multiple serialization formats (JSON, TOML, YAML)
  • Simple file-based storage and retrieval

Installation

pip install ccfg

Optional Dependencies

For additional serialization format support:

  • For TOML support: pip install toml
  • For YAML support: pip install pyyaml

Usage Example

Below is a comprehensive example demonstrating the main features:

from ccfg import CCFG

class ApplicationConfig(CCFG):
    # Custom path for file storage
    path = "configs/app_settings.json"

    # No explicit name, will use class name "ApplicationConfig" as default

    class Database:
        # Custom name for this section
        name = "DatabaseSettings"

        class Connection:
            # No explicit name, will use "Connection" by default
            value = "postgresql://user:password@localhost:5432/mydb"

        class Pooling:
            name = "ConnectionPool"
            value = {"max_connections": 10, "timeout": 30}

    class Logging:
        # Using default name "Logging"

        class Level:
            value = "INFO"

        class Output:
            name = "OutputPath"
            value = "/var/log/app.log"

    class Features:
        # Using a list for complex values
        value = ["authentication", "api", "admin_panel"]


# Convert to dictionary
config_dict = ApplicationConfig.to_dict()
print(config_dict)
# Output:
# {
#   "ApplicationConfig": {
#     "DatabaseSettings": {
#       "Connection": "postgresql://user:password@localhost:5432/mydb",
#       "ConnectionPool": {"max_connections": 10, "timeout": 30}
#     },
#     "Logging": {
#       "Level": "INFO",
#       "OutputPath": "/var/log/app.log"
#     },
#     "Features": ["authentication", "api", "admin_panel"]
#   }
# }

# Save to file using the configured path
ApplicationConfig.dump()  # Saves to configs/app_settings.json

# Save to a different file in YAML format
ApplicationConfig.dump(form="yaml", path="configs/app_config.yaml")

# Load configuration
ApplicationConfig.load()  # Loads from configs/app_settings.json

# Access configuration values
db_connection = ApplicationConfig.Database.Connection.value
log_level = ApplicationConfig.Logging.Level.value
features = ApplicationConfig.Features.value

print(f"Database connection: {db_connection}")
print(f"Log level: {log_level}")
print(f"Enabled features: {', '.join(features)}")

Supported Serialization Formats

  • JSON (default)
  • TOML
  • YAML

License

MIT

Metadata

Release files for ccfg 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ccfg 0.0.4
File Size Uploaded Provenance Actions
ccfg-0.0.4.tar.gz 6.5 kB Without provenance Details for ccfg-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ccfg 0.0.4
File Interpreter ABI Platform Actions
ccfg-0.0.4-py3-none-any.whl Python 3 none any Details for ccfg-0.0.4-py3-none-any.whl

Total release size: 12.0 kB

Release files / ccfg-0.0.4.tar.gz

Download URL ccfg-0.0.4.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0691e291de850e227a17d4bd44e384870c5cb509b9a4a8aec197e036c6e1db45
BLAKE2b-256 checksum
How to use checksums
73fd186004b439cfc78d4c8cadb5ad705c2b9999e4e7e648da7cb2de9e073f66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / ccfg-0.0.4-py3-none-any.whl

Download URL ccfg-0.0.4-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00869d7df81728697bbfa76fc66d1e2ab12d3d4532b75ca88865dc918feacc92
BLAKE2b-256 checksum
How to use checksums
71ef318d23f5c96b94363a9a6ed1ce734cf8ac3f2e4271920422abbf639f9190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Security for ccfg 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page