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:
- ๐ Automatically detects the current environment from environment variables (ENV, ENVIRONMENT, or PROFILE)
- ๐ Looks for environment-specific configuration files like
config-dev.yaml,application-prod.json, etc. - ๐ 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9168556cb15f4549c64ea746df569336f339c8aa49d287aa36ac5b6c98fd6b07
|
|
| MD5 |
d8ccd5c42dc8c7bc25bfd27c8f2e0cc6
|
|
| BLAKE2b-256 |
2fb45ea30ce50883ec28dc34bfa572695004a930ad97ba9347a1fbca936dd950
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a7643ec5b6dcd5339b95fa9ad987a15ef9f62f6ac77dc6747629766363b11fa
|
|
| MD5 |
556ae9914a7bf9e0d20d89e4c94e7d25
|
|
| BLAKE2b-256 |
564f91bd3a9d2af85571a686bf3674fc7750f0048af6680c63d9743903a222cc
|