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.3.tar.gz (4.5 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.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for octus-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2f5163265f0855c09c2f0e942353964d20dafe1c03151d80e21268de0730251d
MD5 56c783d49f6d9d36bd9d957c15651450
BLAKE2b-256 2a383fd47e3dff6351c26eebfb46b30c7df3497b20e35c14bccb0b0b605dc841

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for octus-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d40498038cbd9ae790d667cc9f9481bd8866d4332ebc3f90d75bf0662cae0be8
MD5 f6582dc7e5fd369bfce4c4723d2b0f78
BLAKE2b-256 57d245780a4606eaaf30ce53affcba327f0b9f70cec8a8b9ad0af2ba7060c969

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