Settings Manager
Project description
ZeConfig
ZeConfig is a Python library designed to manage application configurations, making it easier to handle sensitive data and environment-specific settings. It supports configuration files in both TOML and JSON formats and provides utilities for identifying, reading, and parsing configuration files.
Features
- Automatic detection of configuration file location within the current directory or its subdirectories.
- Support for TOML configuration files.
- Environment management (e.g., development, staging, production).
- Easy access to environment-specific keys and values.
Installation
Clone the repository or copy the zeconfig.py file into your project directory.
# Clone the repository
git clone https://github.com/uadson/zeconfig.git
Ensure you have Python 3.11+ installed. If your Python version is below 3.11, you may need to install the tomli library for TOML parsing:
pip install tomli
Usage
1. Initialize ZeConfig
Create an instance of the ZeConfig class:
from zeconfig import ZeConfig
# Initialize with the configuration file name and project name
ze = ZeConfig(settings_file="config.toml", project_name="MyApp")
2. Retrieve Configuration File Location
file_location = ze.get_file_location()
print(f"Configuration file is located at: {file_location}")
3. Read Configuration Data
Parse the TOML configuration file:
config_data = ze.file_reader()
print(config_data)
4. Manage Environment Settings
Set the application environment:
ze.set_env("staging")
Retrieve a value for a specific key in the current environment:
database_url = ze.get_env("DATABASE_URL")
print(f"Database URL: {database_url}")
5. Command-Line Integration
The environment can also be set via command-line arguments:
python your_script.py --dev # Set environment to development
Configuration File Format
Example config.toml
[development]
DATABASE_URL = "sqlite:///dev.db"
SECRET_KEY = "dev-secret"
[staging]
DATABASE_URL = "postgresql://staging-user:password@localhost/staging"
SECRET_KEY = "staging-secret"
[production]
DATABASE_URL = "postgresql://prod-user:password@localhost/production"
SECRET_KEY = "prod-secret"
Error Handling
ZeConfig raises descriptive exceptions for common issues:
FileNotFoundError: Configuration file not found.KeyError: Missing environment or key in the configuration file.ValueError: Unsupported file type or parsing error.RuntimeError: Unexpected runtime errors.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
Contact
For questions or support, please reach out to uadsonpy@gmail.com.
Project details
Release history Release notifications | RSS feed
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 zeconfig-0.0.8.tar.gz.
File metadata
- Download URL: zeconfig-0.0.8.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6002df8ae6c8487e2b00bee706fb043443df5f628ad34a46fd967669d6559ed0
|
|
| MD5 |
8069dc2f8cc527bffa84805620de9dea
|
|
| BLAKE2b-256 |
d88838ca688bd9b281468b45572c00f3db0890ffe82ba9af126d89503ad11b39
|
File details
Details for the file zeconfig-0.0.8-py3-none-any.whl.
File metadata
- Download URL: zeconfig-0.0.8-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a94a7570aa153e9c53306007e8bccf227a14b0ff6368712dfed28085c642e62
|
|
| MD5 |
fa0169f29764735ee7fdd3329abbc1bb
|
|
| BLAKE2b-256 |
866d4f01b2e7398f4c52fde04607c7605e4cc5ddc1883c109ececcd45533d030
|