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.1.2.tar.gz (12.6 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.1.2-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: joy_config-0.1.2.tar.gz
  • Upload date:
  • Size: 12.6 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.1.2.tar.gz
Algorithm Hash digest
SHA256 9168556cb15f4549c64ea746df569336f339c8aa49d287aa36ac5b6c98fd6b07
MD5 d8ccd5c42dc8c7bc25bfd27c8f2e0cc6
BLAKE2b-256 2fb45ea30ce50883ec28dc34bfa572695004a930ad97ba9347a1fbca936dd950

See more details on using hashes here.

File details

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

File metadata

  • Download URL: joy_config-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.0 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a7643ec5b6dcd5339b95fa9ad987a15ef9f62f6ac77dc6747629766363b11fa
MD5 556ae9914a7bf9e0d20d89e4c94e7d25
BLAKE2b-256 564f91bd3a9d2af85571a686bf3674fc7750f0048af6680c63d9743903a222cc

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