Skip to main content

Add your description here

Project description

joy-config ๐ŸŽฎ

A simple, flexible Python configuration loader that automatically detects and loads project configuration files.

โœจ Features

  • ๐Ÿ”„ Multiple Format Support: Compatible with YAML, JSON, INI, ENV, and other configuration file formats
  • ๐Ÿ” Auto Detection: Automatically finds and loads configuration files in your project without requiring explicit paths
  • ๐ŸŒ Environment Awareness: Loads environment-specific configuration files based on environment variables
  • ๐Ÿ”— Config Merging: Intelligently merges base configurations with environment-specific overrides
  • ๐Ÿ”‘ Flexible Access: Access configuration values via attributes or dictionary-style lookups
  • ๐Ÿ“Š Nested Configuration: Full support for nested configuration structures

๐Ÿ“ฆ Installation

pip install joy-config

๐Ÿš€ Quick Start

Auto-loading Configuration

from joy_config.loader import auto_loader

# Automatically detect and load configuration files in your project
config = auto_loader()

# Access configuration items
db_host = config.database.host
# or
db_host = config['database.host']
# or with default value
db_host = config.get('database.host', 'localhost')

Specifying Configuration Files

from joy_config.loader import auto_loader

# Specify a configuration file path
config = auto_loader('config/app_config.yaml')

# Specify an environment
config = auto_loader(env='production')

๐Ÿ“„ Supported Configuration Formats

YAML ๐Ÿ“

database:
  host: localhost
  port: 5432
  username: admin
  password: secret

app:
  debug: false
  log_level: info

JSON ๐Ÿ“

{
  "database": {
    "host": "localhost",
    "port": 5432,
    "username": "admin",
    "password": "secret"
  },
  "app": {
    "debug": false,
    "log_level": "info"
  }
}

INI ๐Ÿ“

[database]
host = localhost
port = 5432
username = admin
password = secret

[app]
debug = false
log_level = info

Environment Variables (.env) ๐Ÿ“

DATABASE_HOST=localhost 
DATABASE_PORT=5432 
DATABASE_USERNAME=admin 
DATABASE_PASSWORD=secret 
APP_DEBUG=false 
APP_LOG_LEVEL=info

๐ŸŒ Environment-Specific Configuration

joy-config supports loading different configuration files based on the current environment:

  1. ๐Ÿ” Automatically detects the current environment from environment variables (ENV, ENVIRONMENT, or PROFILE)
  2. ๐Ÿ“ Looks for environment-specific configuration files like config-dev.yaml, application-prod.json, etc.
  3. ๐Ÿ”„ Intelligently merges base configuration with environment-specific overrides

Example:

# With environment variable ENV=dev
config = auto_loader()  # Will automatically load both config.yaml and config-dev.yaml

๐Ÿ”ง Advanced Usage

Configuration Merging ๐Ÿ”„

# Base config (config.yaml)
# database:
#   host: localhost
#   port: 5432
#   username: admin

# Environment config (config-prod.yaml)
# database:
#   host: db.example.com
#   password: prod-secret

# Merged configuration
# config.database.host == "db.example.com"
# config.database.port == 5432
# config.database.username == "admin"
# config.database.password == "prod-secret"

Converting to Dictionary ๐Ÿ”„

# Convert the configuration object to a dictionary
config_dict = config.as_dict()

๐Ÿ“œ License

MIT


This README provides comprehensive information about the project's main features, installation instructions, usage examples, and advanced usage patterns. The document is structured to help users quickly understand how to use the library effectively. ๐Ÿš€

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

joy_config-0.2.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

joy_config-0.2.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file joy_config-0.2.0.tar.gz.

File metadata

  • Download URL: joy_config-0.2.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for joy_config-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2d5018aad622fb75b9feb8933003272baf8d3fea3fe417a4fb32d142f0a58bcd
MD5 145c16ddbc56fa2abfd340caef42ac8e
BLAKE2b-256 f537a45c79bd962910c5144a6dec9d38df0e1734e5dbc5aae520c4d3b5c0effc

See more details on using hashes here.

File details

Details for the file joy_config-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: joy_config-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for joy_config-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ebef751765cb7e7af36f5360c70d757c57147e5075b9572a781bf14235e4e77
MD5 8f1daf9d92738985bbe194233f0e328f
BLAKE2b-256 1b9a1352eae7f1734ae35d434deab07b2a567720298a5cb36d2c9596772be4d3

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