Skip to content

vzool/vzool-config.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A class for managing configuration settings in a SQLite database.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors