Skip to main content

A simple database management abstraction layer built on SQLAlchemy

Project description

🚀 DBFlux: Lightweight Database Management Library

PyPI - Version Python License Downloads

🛠️ Version 1.0.0

🌟 Introduction

DBFlux is a lightweight, easy-to-use library built on top of SQLAlchemy to simplify database operations in Python.

It provides a streamlined interface for connecting to databases, managing sessions, and performing CRUD operations with minimal effort.


Features

  • 🔁 Automatic Transaction Management
  • 🛠️ Session Handling
  • 🔗 Flexibility – Supports multiple database engines via SQLAlchemy
  • ⚡ Lightweight & Efficient
  • 🔍 Advanced Filtering
  • 📥 Data Insertion
  • ✏️ Data Modification
  • 📄 Easy Pagination
  • 🛡️ Safe Deletion
  • 📦 Consistent Output Handling

📚 Requirements

  • Python 3.8+
  • SQLAlchemy >= 2.0

🔧 Installation

Install dbflux via pip:

pip install dbflux

Or install from source:

git clone https://github.com/abbas-bachari/dbflux.git
cd dbflux
pip install .

💡 Quick Start

from dbflux  import Sqlite,DBModel
from sqlalchemy import Column, Integer, String, Float
from sqlalchemy.orm import declarative_base
from time import time

Base=declarative_base()
db = Sqlite(db_name="example.db")


class User(Base):
    __tablename__ = "users"
    id = Column(Integer, primary_key=True)
    name = Column(String(50))
    email = Column(String(100))

class Order(Base):
    __tablename__ = "orders"
    order_id = Column(Integer, primary_key=True)
    product = Column(String, nullable=False)
    price = Column(Float, nullable=False)
    time = Column(Integer, nullable=False)

db.create_tables(Base)


users=DBModel(User,db)
orders=DBModel(Order,db)


users_data=[
    {"id": 1, "name": "Alice", "email": "alice@test.com"},
    {"id": 2, "name": "Bob", "email": "bob@test.com"},
    {"id": 3, "name": "Carol", "email": "carol@test.com"}
]

orders_data=[
    {"order_id": 1, "product": "Product A", "price": 100, "time": time()},
    {"order_id": 2, "product": "Product B", "price": 200, "time": time()},
    {"order_id": 3, "product": "Product C", "price": 300, "time": time()}
]

users.insert(users_data)
orders.insert(orders_data)

💡 Examples Usage DBFactory

from dbflux import DBFactory,DBModel
from sqlalchemy import Column, Integer, String, Float
from sqlalchemy.orm import declarative_base
from time import time

Base = declarative_base()

class Order(Base):
    __tablename__ = "orders"
    order_id = Column(Integer, primary_key=True)
    product = Column(String, nullable=False)
    price = Column(Float, nullable=False)
    time = Column(Integer, nullable=False)



factory = DBFactory(db_name="data.db")
db = factory.create("sqlite")
db.create_tables(Base)
orders_db = DBModel(Order ,db)


order = Order(order_id=1, product="Product A", price=100, time=time())
orders_db.insert( order)

orders = orders_db.get(limit=1).to_json()

print(orders)

Result:

[
    {
        "price": 100.0,
        "time": 1755565113.9635222,
        "order_id": 1,
        "product": "Product A"
    }
]

🔹 Supported Database Types

Type Aliases
SQLite sqlite
MySQL mysql
PostgreSQL postgres, postgresql
MariaDB mariadb
Oracle oracle
DB2 db2, ibmdb2
Firebird firebird
MSSQL mssql, sqlserver

🔹 Examples for Different Databases

from dbflux.databases import Sqlite, MySQL, PostgreSQL

# Example 1: SQLite
sqlite_db = Sqlite(db_name="data.db")
sqlite_db.create_tables(Base)
sqlite_db.insert(model_class= Order ,data=Order(order_id=10, product="SQLite Product", price=50, time=time()))

# Example 2: MySQL
mysql_db = MySQL(db_name="test_db",username="root", password="password", host="localhost", )
mysql_db.create_tables(Base)
mysql_db.insert(model_class= Order ,data=Order(order_id=11, product="MySQL Product", price=60, time=time()))

# Example 3: PostgreSQL
postgres_db = PostgreSQL(db_name="test_db",username="postgres", password="secret", host="localhost")
postgres_db.create_tables(Base)
postgres_db.insert(model_class= Order ,data=Order(order_id=12, product="PostgreSQL Product", price=70, time=time()))

🎯 Summary of Features

✅ CRUD Operations

✅ Bulk Insert & Bulk Update

✅ Advanced Filtering (OR/AND/Range)

✅ Pagination

✅ JSON Output

✅ Transaction Safety

✅ Direct SQLAlchemy Access via BaseDB


📖 Documentation

For more details, visit the official SQLAlchemy documentation.


📜 License

This project is licensed under the MIT License.


👤 Publisher / ناشر

Abbas Bachari / عباس بچاری


💖 Sponsor

Support development by sponsoring on Github Sponsors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbflux-1.0.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbflux-1.0.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file dbflux-1.0.0.tar.gz.

File metadata

  • Download URL: dbflux-1.0.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dbflux-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a2e829c1af61f8b9e33ab19162ba2a497a3f5a7d526e1df73a0c79a58b558b6f
MD5 0d95358959791e66707adacd0abe837f
BLAKE2b-256 be43c54c399edd8820bc92bc9e1310e32d4e80030894e07b3aa9d7e00d9280cc

See more details on using hashes here.

File details

Details for the file dbflux-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dbflux-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for dbflux-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab14ac3173b41ba98539d40da7d9dac94f5e0254f1ec27e5d1edc75ef8952948
MD5 9b7e81eb5a821148df6e33ab793265c0
BLAKE2b-256 3862b02fd3a2fd41d257b24468206b5e09d816aec544d8ee10bfca785810eb92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page