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.2.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.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: octus-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 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.2.tar.gz
Algorithm Hash digest
SHA256 4ee3bd8a6d3687226ad9425b60e1a9937540d3c9f1fcb25f4a072e35ef8ef2b4
MD5 bab37ee1bfef5f278ad7e4029b67b2eb
BLAKE2b-256 dd64912041876b8ab3ba27c0c5566a6bbf3ae363f9d39217bbfd0c7401f34a9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: octus-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 81a01ec448113fdec08ff167a6fb3f7114fda26a0db5514268e6d777f7086f1e
MD5 717ff78844fa3d91c2cb88023fd26443
BLAKE2b-256 042744d1243447c7565b6f4d9d12e8fe26b278b3c267544411a6b292996da4a3

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