<h1 align="center">π Dabas: Lightweight Database Management Library</h1>
<p align="center">
<a href="https://pypi.org/project/Dabas/"><img src="https://img.shields.io/pypi/v/Dabas?style=plastic" alt="PyPI - Version"></a>
<a href="https://github.com/abbas-bachari/Dabas"><img src="https://img.shields.io/badge/Python%20-3.7+-green?style=plastic&logo=Python" alt="Python"></a>
<a href="https://pypi.org/project/Dabas/"><img src="https://img.shields.io/pypi/l/Dabas?style=plastic" alt="License"></a>
<a href="https://pepy.tech/project/Dabas"><img src="https://pepy.tech/badge/Dabas?style=flat-plastic" alt="Downloads"></a>
</p>
## π οΈ Version 1.0.5
## π **Introduction**
#### **Dabas** 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** β Ensures safe commits and rollbacks.
- π οΈ **Session Handling** β Provides a clean API for managing database sessions.
- π **Flexibility** β Supports multiple database engines via SQLAlchemy.
- β‘ **Lightweight & Efficient** β Designed to be minimal while offering essential functionality.
- π **Advanced Filtering** β Supports OR/AND/range conditions.
- π₯ **Data Insertion** β Insert and bulk insert support.
- βοΈ **Data Modification** β Update and bulk update capabilities.
- π **Easy Pagination** β Simplifies data navigation.
- π‘οΈ **Safe Deletion** β Protects data with rollback support.
- π¦ **Consistent Output Handling** β Ensures structured data response.
---
## π **Requirements**
- **Python 3.7+**
- **SQLAlchemy >= 1.4**
---
## π§ **Installation**
Install **Dabas** via **pip**:
```bash
pip install Dabas
```
## π‘ **Quick Start**
Hereβs how you can **quickly set up and use Dabas** in your project.
```python
from Dabas import DatabaseManager, EngineFactory
from sqlalchemy import Column, Integer, Float, String
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)
def __init__(self, order_id, product, price, time):
self.order_id = order_id
self.product = product
self.price = price
self.time = time
# Example data
order_1 = {"order_id": 1, "product": "product_1", "price": 100, "time": time()}
order_2 = Order(order_id=2, product="product_2", price=200, time=time())
# Database setup
engine = EngineFactory("data.db").sqlite()
db = DatabaseManager(engine=engine, base=Base)
# Create tables if they don't exist
db.create_tables()
# Insert records
db.insert(Order(**order_1))
db.insert(order_2)
# Query data
orders = db.get(Order, limit=2).to_json()
print(orders)
```
## π₯οΈ **Expected Output**
```json
[
{
"order_id": 1,
"price": 100.0,
"product": "product_1",
"time": 1746916053.5904622
},
{
"order_id": 2,
"price": 200.0,
"product": "product_2",
"time": 1746916053.5904622
}
]
```
## **Advanced Examples with Dabas**
### 1οΈβ£ ***Bulk Insert Data Efficiently***
```python
# Insert multiple orders in one transaction
orders = [
{"order_id": 3, "product": "product_3", "price": 150, "time": time()},
{"order_id": 4, "product": "product_4", "price": 250, "time": time()},
{"order_id": 5, "product": "product_5", "price": 350, "time": time()},
]
order = Order(order_id=2, product="product_2", price=200, time=time())
orders.append(order)
result=db.insert(Order,orders)
print(result)
>>> 4
```
#### β
Faster insertion
#### β
Minimizes database overhead
### 2οΈβ£ ***Query with Filters (OR, AND, Range)***
```python
# Get orders where price is between 100 and 200
filters=[Order.price.between(100, 200)]
filtered_orders = db.search(model_class, conditions=filters).to_json()
# Get orders with specific conditions (OR)
from sqlalchemy import or_
or_filters=[or_(Order.product=="product_1",Order.price==250)]
or_filtered_orders =db.search(model_class, conditions=or_filters).to_json()
# Get orders with specific conditions (AND)
and_filters=[
Order.product=="product_1",
Order.price==250
]
and_filtered_orders =db.search(model_class, conditions=and_filters).to_json()
print(filtered_orders, or_filtered_orders, and_filtered_orders)
```
#### β
**Flexible filtering with OR/AND and range condition**
### 3οΈβ£ ***Update Records with Bulk Update***
```python
# Update multiple records at once
update_data = [{"order_id": 3, "product": "Updated_Product_3"}, {"order_id": 4, "price": 275}]
db.bulk_update(Order, update_data)
```
#### β
**Easily update multiple records in one operation**
### 4οΈβ£ ***Safe Deletion with Rollback Suppor***
```python
# Delete an order safely
conditions=[Order.order_id==5]
db.delete(Order, conditions=conditions)
```
#### β
**Ensures rollback support in case of errors**
### 5οΈβ£ ***Pagination for Large Dataset***
```python
# Get paginated results (2 items per page)
page_1 = db.paginate(page=1, per_page=2).to_json()
page_2 = db.paginate(page=2, per_page=2).to_json()
print(page_1, page_2)
```
#### β
**Easier navigation in large datasets**
---
### π― Summary of New Features
#### β
Bulk insert for efficient data handling
#### β
Advanced filtering with OR/AND/Range conditions
#### β
Bulk updates for multiple records at once
#### β
Safe deletion with rollback protection
#### β
Pagination for large queries
## π **Documentation**
For more details, visit the [official SQLAlchemy documentation](https://docs.sqlalchemy.org/).
## π **License**
This project is licensed under the **MIT License**.
## π **Sponsor**
Support development by sponsoring on **[Github Sponsors](https://github.com/sponsors/abbas-bachari)**.
Raw data
{
"_id": null,
"home_page": "https://github.com/abbas-bachari/Dabas",
"name": "Dabas",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "Dabas, Database, Database-Management, Dabas-python, SQLAlchemy, SQLAlchemy-python, Dabas-SQLAlchemy, Dabas-SQLAlchemy-python, SQLAlchemy-Database-Management",
"author": "Abbas Bachari",
"author_email": "abbas-bachari@hotmail.com",
"download_url": "https://files.pythonhosted.org/packages/cb/9f/f58390e22c3233768a97abf884617f857a9ec7bafa0b9344b11389953529/dabas-1.0.5.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\ud83d\ude80 Dabas: Lightweight Database Management Library</h1>\r\n\r\n<p align=\"center\">\r\n<a href=\"https://pypi.org/project/Dabas/\"><img src=\"https://img.shields.io/pypi/v/Dabas?style=plastic\" alt=\"PyPI - Version\"></a>\r\n<a href=\"https://github.com/abbas-bachari/Dabas\"><img src=\"https://img.shields.io/badge/Python%20-3.7+-green?style=plastic&logo=Python\" alt=\"Python\"></a>\r\n <a href=\"https://pypi.org/project/Dabas/\"><img src=\"https://img.shields.io/pypi/l/Dabas?style=plastic\" alt=\"License\"></a>\r\n <a href=\"https://pepy.tech/project/Dabas\"><img src=\"https://pepy.tech/badge/Dabas?style=flat-plastic\" alt=\"Downloads\"></a>\r\n</p>\r\n\r\n## \ud83d\udee0\ufe0f Version 1.0.5\r\n\r\n## \ud83c\udf1f **Introduction**\r\n\r\n#### **Dabas** is a lightweight, easy-to-use library built on top of **SQLAlchemy** to simplify database operations in Python. \r\n#### It provides a streamlined interface for **connecting to databases**, **managing sessions**, and **performing CRUD operations** with minimal effort.\r\n\r\n---\r\n\r\n## \u2728 **Features**\r\n\r\n- \ud83d\udd01 **Automatic Transaction Management** \u2013 Ensures safe commits and rollbacks.\r\n- \ud83d\udee0\ufe0f **Session Handling** \u2013 Provides a clean API for managing database sessions.\r\n- \ud83d\udd17 **Flexibility** \u2013 Supports multiple database engines via SQLAlchemy.\r\n- \u26a1 **Lightweight & Efficient** \u2013 Designed to be minimal while offering essential functionality.\r\n- \ud83d\udd0d **Advanced Filtering** \u2013 Supports OR/AND/range conditions.\r\n- \ud83d\udce5 **Data Insertion** \u2013 Insert and bulk insert support.\r\n- \u270f\ufe0f **Data Modification** \u2013 Update and bulk update capabilities.\r\n- \ud83d\udcc4 **Easy Pagination** \u2013 Simplifies data navigation.\r\n- \ud83d\udee1\ufe0f **Safe Deletion** \u2013 Protects data with rollback support.\r\n- \ud83d\udce6 **Consistent Output Handling** \u2013 Ensures structured data response.\r\n\r\n---\r\n\r\n## \ud83d\udcda **Requirements**\r\n\r\n- **Python 3.7+**\r\n- **SQLAlchemy >= 1.4**\r\n\r\n---\r\n\r\n## \ud83d\udd27 **Installation**\r\n\r\nInstall **Dabas** via **pip**:\r\n\r\n```bash\r\npip install Dabas\r\n```\r\n\r\n## \ud83d\udca1 **Quick Start**\r\n\r\nHere\u2019s how you can **quickly set up and use Dabas** in your project.\r\n\r\n```python\r\nfrom Dabas import DatabaseManager, EngineFactory\r\nfrom sqlalchemy import Column, Integer, Float, String\r\nfrom sqlalchemy.orm import declarative_base\r\nfrom time import time\r\n\r\nBase = declarative_base()\r\n\r\nclass Order(Base):\r\n __tablename__ = \"orders\"\r\n\r\n order_id = Column(Integer, primary_key=True)\r\n product = Column(String, nullable=False)\r\n price = Column(Float, nullable=False)\r\n time = Column(Integer, nullable=False)\r\n\r\n def __init__(self, order_id, product, price, time):\r\n self.order_id = order_id\r\n self.product = product\r\n self.price = price\r\n self.time = time\r\n\r\n# Example data\r\norder_1 = {\"order_id\": 1, \"product\": \"product_1\", \"price\": 100, \"time\": time()}\r\norder_2 = Order(order_id=2, product=\"product_2\", price=200, time=time())\r\n\r\n# Database setup\r\nengine = EngineFactory(\"data.db\").sqlite()\r\ndb = DatabaseManager(engine=engine, base=Base)\r\n\r\n# Create tables if they don't exist\r\ndb.create_tables()\r\n\r\n# Insert records\r\ndb.insert(Order(**order_1))\r\ndb.insert(order_2)\r\n\r\n# Query data\r\norders = db.get(Order, limit=2).to_json()\r\nprint(orders)\r\n```\r\n\r\n## \ud83d\udda5\ufe0f **Expected Output**\r\n\r\n```json\r\n[\r\n {\r\n \"order_id\": 1,\r\n \"price\": 100.0,\r\n \"product\": \"product_1\",\r\n \"time\": 1746916053.5904622\r\n },\r\n {\r\n \"order_id\": 2,\r\n \"price\": 200.0,\r\n \"product\": \"product_2\",\r\n \"time\": 1746916053.5904622\r\n }\r\n]\r\n```\r\n\r\n## **Advanced Examples with Dabas**\r\n\r\n### 1\ufe0f\u20e3 ***Bulk Insert Data Efficiently***\r\n\r\n```python\r\n# Insert multiple orders in one transaction\r\norders = [\r\n {\"order_id\": 3, \"product\": \"product_3\", \"price\": 150, \"time\": time()},\r\n {\"order_id\": 4, \"product\": \"product_4\", \"price\": 250, \"time\": time()},\r\n {\"order_id\": 5, \"product\": \"product_5\", \"price\": 350, \"time\": time()},\r\n]\r\norder = Order(order_id=2, product=\"product_2\", price=200, time=time())\r\norders.append(order)\r\n\r\nresult=db.insert(Order,orders)\r\nprint(result)\r\n>>> 4\r\n```\r\n\r\n#### \u2705 Faster insertion\r\n\r\n#### \u2705 Minimizes database overhead\r\n\r\n\r\n\r\n### 2\ufe0f\u20e3 ***Query with Filters (OR, AND, Range)***\r\n\r\n```python\r\n# Get orders where price is between 100 and 200\r\nfilters=[Order.price.between(100, 200)]\r\n\r\nfiltered_orders = db.search(model_class, conditions=filters).to_json()\r\n\r\n\r\n\r\n# Get orders with specific conditions (OR)\r\nfrom sqlalchemy import or_\r\nor_filters=[or_(Order.product==\"product_1\",Order.price==250)]\r\nor_filtered_orders =db.search(model_class, conditions=or_filters).to_json()\r\n\r\n\r\n# Get orders with specific conditions (AND)\r\nand_filters=[\r\n Order.product==\"product_1\",\r\n Order.price==250\r\n ]\r\nand_filtered_orders =db.search(model_class, conditions=and_filters).to_json()\r\n\r\n\r\nprint(filtered_orders, or_filtered_orders, and_filtered_orders)\r\n```\r\n\r\n#### \u2705 **Flexible filtering with OR/AND and range condition**\r\n\r\n\r\n### 3\ufe0f\u20e3 ***Update Records with Bulk Update***\r\n\r\n```python\r\n# Update multiple records at once\r\nupdate_data = [{\"order_id\": 3, \"product\": \"Updated_Product_3\"}, {\"order_id\": 4, \"price\": 275}]\r\ndb.bulk_update(Order, update_data)\r\n```\r\n\r\n#### \u2705 **Easily update multiple records in one operation**\r\n\r\n### 4\ufe0f\u20e3 ***Safe Deletion with Rollback Suppor***\r\n\r\n```python\r\n# Delete an order safely\r\nconditions=[Order.order_id==5]\r\ndb.delete(Order, conditions=conditions)\r\n```\r\n\r\n#### \u2705 **Ensures rollback support in case of errors**\r\n\r\n\r\n### 5\ufe0f\u20e3 ***Pagination for Large Dataset***\r\n\r\n```python\r\n# Get paginated results (2 items per page)\r\npage_1 = db.paginate(page=1, per_page=2).to_json()\r\npage_2 = db.paginate(page=2, per_page=2).to_json()\r\n\r\nprint(page_1, page_2)\r\n```\r\n\r\n#### \u2705 **Easier navigation in large datasets**\r\n\r\n---\r\n\r\n### \ud83c\udfaf Summary of New Features\r\n\r\n#### \u2705 Bulk insert for efficient data handling\r\n#### \u2705 Advanced filtering with OR/AND/Range conditions\r\n#### \u2705 Bulk updates for multiple records at once\r\n#### \u2705 Safe deletion with rollback protection\r\n#### \u2705 Pagination for large queries\r\n\r\n\r\n## \ud83d\udcd6 **Documentation**\r\n\r\nFor more details, visit the [official SQLAlchemy documentation](https://docs.sqlalchemy.org/).\r\n\r\n## \ud83d\udcdc **License**\r\n\r\nThis project is licensed under the **MIT License**.\r\n\r\n## \ud83d\udc96 **Sponsor** \r\n\r\nSupport development by sponsoring on **[Github Sponsors](https://github.com/sponsors/abbas-bachari)**.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library for Database Management",
"version": "1.0.5",
"project_urls": {
"Documentation": "https://github.com/abbas-bachari/Dabas",
"Homepage": "https://github.com/abbas-bachari/Dabas",
"Source": "https://github.com/abbas-bachari/Dabas/",
"Tracker": "https://github.com/abbas-bachari/Dabas/issues"
},
"split_keywords": [
"dabas",
" database",
" database-management",
" dabas-python",
" sqlalchemy",
" sqlalchemy-python",
" dabas-sqlalchemy",
" dabas-sqlalchemy-python",
" sqlalchemy-database-management"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8f52f54bd33040300f876d629260f824b66e39f626bba30a94c07ada26fc1e27",
"md5": "65e173c8fd052433907d30ae604ca9f2",
"sha256": "c281365735f6a50f17ef0e68232f5efad211ea5d1a8b85d522f914e5ba970501"
},
"downloads": -1,
"filename": "dabas-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "65e173c8fd052433907d30ae604ca9f2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9507,
"upload_time": "2025-07-13T15:15:36",
"upload_time_iso_8601": "2025-07-13T15:15:36.512222Z",
"url": "https://files.pythonhosted.org/packages/8f/52/f54bd33040300f876d629260f824b66e39f626bba30a94c07ada26fc1e27/dabas-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "cb9ff58390e22c3233768a97abf884617f857a9ec7bafa0b9344b11389953529",
"md5": "f08a7a271f2a7c96dfa142eb2617e8e8",
"sha256": "256882f880ee5546d54ade87dae597f66c835bd0863bfe5609961c29998e4cbc"
},
"downloads": -1,
"filename": "dabas-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "f08a7a271f2a7c96dfa142eb2617e8e8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8944,
"upload_time": "2025-07-13T15:15:37",
"upload_time_iso_8601": "2025-07-13T15:15:37.455940Z",
"url": "https://files.pythonhosted.org/packages/cb/9f/f58390e22c3233768a97abf884617f857a9ec7bafa0b9344b11389953529/dabas-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-13 15:15:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "abbas-bachari",
"github_project": "Dabas",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "SQLAlchemy",
"specs": [
[
">=",
"1.4"
]
]
}
],
"lcname": "dabas"
}