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.0.tar.gz (4.2 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.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: octus-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 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.0.tar.gz
Algorithm Hash digest
SHA256 386a82571cc6c3375630280cd7dabf75ab509616bcc6afd238d05fb5ee54e9c6
MD5 48e8c205def182a7c14a03a2fbb39145
BLAKE2b-256 2bd7f9e09f48ab94023e2364a3ff6d7b288e40510bfd86c6d115cc442632c32c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: octus-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba4ae95d55674407a19d42967efcf91fe05ea825e786f451e34a5298e4978e9c
MD5 ab050bd0e75a9ac65fea222ceb6a96c8
BLAKE2b-256 56795862554babb1721e181857f4c14aea5e739f8ee921364c08f56e78d1a1fd

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