Skip to main content

A Python package designed to simplify configuration management for applications. It allows you to load configurations from YAML files, with support for environment-specific overrides and Pydantic for schema validation.

Project description

Octus

A Python package designed to simplify configuration management for applications. It allows you to load configurations from YAML files, with support for environment-specific overrides and Pydantic for schema validation.

Installation

pip install octus

Usage

First, define your configuration schema using Pydantic:

# my_app/config.py
from pydantic import BaseModel

class AppConfig(BaseModel):
    app_name: str
    version: str
    debug_mode: bool = False

Next, create your configuration file (e.g., config.yaml):

# config.yaml
app_name: MyAwesomeApp
version: 1.0.0
debug_mode: true

You can also create environment-specific configuration files, like config.development.yaml or config.production.yaml. If the APP_ENV environment variable is set (e.g., export APP_ENV=development), ConfigLoader will attempt to load config.{APP_ENV}.yaml if it exists, overriding values from config.yaml.

Finally, use Octopus to load your configuration:

# main.py
import os
from octus.core import Octus
from my_app.config import AppConfig

# Optional: Set environment variable for environment-specific config
# os.environ['ENV_TYPE'] = 'development' # Default env_var is ENV_TYPE

# Example 1: Basic usage with default env_var (ENV_TYPE)
config_loader = Octus.load(base_path=".", config_model=AppConfig)
print(f"App Name (default env): {config_loader.app_name}")

# Example 2: Specifying a different environment variable (e.g., APP_ENV)
os.environ['APP_ENV'] = 'production'
config_loader_env = Octus.load(base_path=".", env_var="APP_ENV", config_model=AppConfig)
print(f"App Name (APP_ENV): {config_loader_env.app_name}")

# Example 3: Loading without an environment variable (if no env_var is set)
os.environ.pop('ENV_TYPE', None) # Clear ENV_TYPE if set
os.environ.pop('APP_ENV', None) # Clear APP_ENV if set
config_loader_no_env = Octus.load(base_path=".", config_model=AppConfig)
print(f"App Name (no env): {config_loader_no_env.app_name}")

print(f"App Name: {config.app_name}")
print(f"Version: {config.version}")
print(f"Debug Mode: {config.debug_mode}")

License

This project is licensed under the MIT License.

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

octus-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

octus-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file octus-0.1.1.tar.gz.

File metadata

  • Download URL: octus-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for octus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bec23453cc3111f20ec71635e02489bbc481a4b8e4a73d4b38e466b441846313
MD5 e8fbdba69e954b37cd02e89ef83cf804
BLAKE2b-256 d922e3d9f2a83f97b52fb1db42db475efdf94d95cf64250d71ecb80afda1b7b3

See more details on using hashes here.

File details

Details for the file octus-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: octus-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for octus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 114c9c090ca69f7cceda80a0c3695acfac747770dbae52b21eb0f4c6fb4f5965
MD5 d9cf6b70ccb31125a7fb2f47f5c032fd
BLAKE2b-256 f5a0c8214c27719f9f23ace80dc5ff92a78fbbc303681d5ae2f0af467d8c23bf

See more details on using hashes here.

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