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.
- 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.
pip install vzool-config1- Import the Class:
from vzool_config import ConfigManager2- Create an Instance:
config = ConfigManager(db_file="my_config.db") # Customize the database filename3- 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 value5- Delete Configuration Values:
config.delete("max_items")6- Close the Database Connection:
config.close()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()- 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.
Contributions are welcome! Please feel free to fork the repository, make changes, and submit a pull request.