Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

3.0.0

Choose a tag to compare

@Danex-Exe Danex-Exe released this 12 Dec 17:26
· 5 commits to main since this release

Welcome to DBase documentation. For the latest documentation, visit our GitHub repository.

Quick Links

Installation

pip install dbase

Basic Example

from dbase import DataBase

# Create or open a database
db = DataBase(file_path="data.json")

# Store data
db["name"] = "Alice"
db.score = 95

# Retrieve data
print(db["name"])  # Alice
print(db.score)    # 95

# Use as context manager
with DataBase(file_path="session.json") as session:
    session.user = "admin"
    session.timestamp = "2024-01-01"

API Reference

DataBase Class

class DataBase(file_path=None, show_logs=True, is_temp=False)

Parameters:

  • file_path (str, optional): Path to JSON file for persistent storage
  • show_logs (bool): Enable/disable logging (default: True)
  • is_temp (bool): Create temporary in-memory database (default: False)

Methods:

  • get(key, default=None): Get value with fallback
  • pop(key, default=None): Remove and return value
  • update(**kwargs): Update multiple values
  • clear(): Remove all data
  • items(): Return key-value pairs
  • keys(): Return all keys
  • values(): Return all values

Examples

Example 1: Basic CRUD Operations

db = DataBase("users.json")

# Create
db["user1"] = {"name": "Alice", "age": 30}

# Read
user = db["user1"]

# Update
db["user1"]["age"] = 31

# Delete
del db["user1"]

Example 2: Configuration Storage

config = DataBase("config.json")

# Set configuration
config.database.host = "localhost"
config.database.port = 5432
config.app.debug = True

# Get configuration
host = config.database.host

Example 3: Temporary Data

# Temporary in-memory database
cache = DataBase(is_temp=True)

# Store temporary data
cache.session_token = "abc123"
cache.timestamp = "2024-01-01T12:00:00"

# Data is lost when program ends

Best Practices

  1. Use context managers for automatic cleanup:

    with DataBase("data.json") as db:
        # Work with database
  2. Handle missing keys safely:

    value = db.get("missing_key", default="default_value")
  3. Use appropriate storage:

    • Persistent files for long-term storage
    • Temporary databases for caching
  4. Enable logging during development:

    db = DataBase("data.json", show_logs=True)

Troubleshooting

Common Issues

  1. File not found errors: Ensure the directory exists before creating database
  2. Permission errors: Check file permissions
  3. JSON decode errors: Verify file contains valid JSON
  4. Type errors: Ensure you're using string keys

Getting Help

  • Check the GitHub Issues
  • Review the source code
  • Submit a bug report with reproduction steps

License

MIT License - see LICENSE file for details.

Support

This project is maintained by Daniil Alekseev. For support, please open an issue on GitHub.

Full Changelog: https://github.com/Danex-Exe/dbase/commits/3.0.0