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.1

🌟 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.1.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.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbflux-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2e19ecd37ffebc609aee91c311a20674bf518bd4718eea371957496cde59ea1e
MD5 ad94b5aa93c89a10e7de37037038723b
BLAKE2b-256 b526fb3790f3f31d1db8974f91889ea4935b43e81449a40fa59be48670d174cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dbflux-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40fcd654a134d1845dbb07cfd134bd801a4fa65690e8cb066021324b15d19287
MD5 3996da7324338e1c46b5748f6b75190a
BLAKE2b-256 34358eb4da75772ec7043a37071c3ee2e36d3b583139d6ed47aa68d0d88ad4f3

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