An open API service indexing awesome lists of open source software.

https://github.com/vzool/vzool-config.py

A class for managing configuration settings in a SQLite database.
https://github.com/vzool/vzool-config.py

config python3 sqlite3

Last synced: 9 months ago
JSON representation

A class for managing configuration settings in a SQLite database.

Awesome Lists containing this project

README

          

# 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:

```shell
pip install vzool-config
```

## Usage:

1- Import the Class:

```python
from vzool_config import ConfigManager
```

2- Create an Instance:

```python
config = ConfigManager(db_file="my_config.db") # Customize the database filename
```

3- Set Configuration Values:

```python
config.set("api_key", "your_api_key")
config.set("enabled", True)
config.set("max_items", 10)
```

4- Get Configuration Values:

```python
api_key = config.get("api_key")
enabled = config.get("enabled", False) # Provide a default value
```

5- Delete Configuration Values:
```python
config.delete("max_items")
```

6- Close the Database Connection:

```python
config.close()
```

## Example:

```python
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.