A class for managing configuration settings in a SQLite database.
Project description
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.
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
File details
Details for the file vzool_config-0.0.1.tar.gz
.
File metadata
- Download URL: vzool_config-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77ece8db9d0aa85b59a9e7efefac1beba04e3808329747721b8c1f6e1dfd761d |
|
MD5 | cc824c4a5c62f5e61f5975bf95475dbb |
|
BLAKE2b-256 | 78a85394b924f102ee90472c19b3cbc79e08f3b4cd234fa4e88fdc3e8589e948 |
File details
Details for the file vzool_config-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: vzool_config-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0263d0f8c1204a6f578c3dd83058ca6ab4a7dec069556c0cbd2338d4c6e8b36 |
|
MD5 | 67abaa23f4c4e95cc475cc2cfea232f0 |
|
BLAKE2b-256 | bf70e33c048e05623f6a50874b8e6918c6bdcfd776ac1d8472a7d35c86c64a5c |