ConfigManager: A Python Class for Managing Configuration Settings
Purpose:
The ConfigManager class provides a convenient way to store and retrieve configuration settings in a SQLite database. It offers a simple interface for setting, getting, and deleting configuration values.
Features:
- SQLite Database: Stores configuration settings in a SQLite database for persistence.
- Data Type Support: Handles various data types including strings, integers, floats, decimals, booleans, and JSON objects.
- Automatic Table Creation: Creates the necessary table in the database if it doesn't exist.
- Error Handling: Provides clear error messages for invalid data types or database operations.
- Testing: Includes a built-in test function to ensure proper functionality.
Installation:
pip install vzool-config
Usage:
1- Import the Class:
from vzool_config import ConfigManager
2- Create an Instance:
config = ConfigManager(db_file="my_config.db") # Customize the database filename
3- Set Configuration Values:
config.set("api_key", "your_api_key")
config.set("enabled", True)
config.set("max_items", 10)
4- Get Configuration Values:
api_key = config.get("api_key")
enabled = config.get("enabled", False) # Provide a default value
5- Delete Configuration Values:
config.delete("max_items")
6- Close the Database Connection:
config.close()
Example:
if __name__ == "__main__":
config = ConfigManager()
config.set("name", "John Doe")
config.set("age", 30)
config.set("preferences", {"color": "blue", "food": "pizza"})
name = config.get("name")
age = config.get("age")
preferences = config.get("preferences")
print(name) # Output: John Doe
print(age) # Output: 30
print(preferences) # Output: {'color': 'blue', 'food': 'pizza'}
config.close()
Additional Notes:
- The ConfigManager class is designed for simplicity and ease of use.
- For more complex configuration scenarios, consider using specialized libraries or frameworks.
- Ensure that the SQLite database file has appropriate permissions.
Contributing:
Contributions are welcome! Please feel free to fork the repository, make changes, and submit a pull request.
Metadata
Release files for vzool-config 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vzool_config-0.0.1.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vzool_config-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / vzool_config-0.0.1.tar.gz
| Download URL | vzool_config-0.0.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77ece8db9d0aa85b59a9e7efefac1beba04e3808329747721b8c1f6e1dfd761d
|
|
BLAKE2b-256 checksum How to use checksums |
78a85394b924f102ee90472c19b3cbc79e08f3b4cd234fa4e88fdc3e8589e948
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.5
|
Release files / vzool_config-0.0.1-py3-none-any.whl
| Download URL | vzool_config-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0263d0f8c1204a6f578c3dd83058ca6ab4a7dec069556c0cbd2338d4c6e8b36
|
|
BLAKE2b-256 checksum How to use checksums |
bf70e33c048e05623f6a50874b8e6918c6bdcfd776ac1d8472a7d35c86c64a5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.5
|