Skip to main content

Python Data Access (easydb)

PyPI Version Python Versions

A lightweight, fast, and secure database access layer and query builder for MySQL, SQLite, and Flatfile databases.

easydb simplifies database interactions for your Python applications by providing a single, unified interface. Write your data access logic once, and seamlessly migrate from a local Flatfile or SQLite database to a production MySQL database without changing a single line of query code.

💡 Why choose easydb?

  • Unified Interface: Swap database engines instantly. Start with a flat file, move to SQLite, and scale to MySQL using the exact same Python code.
  • Query Builder: Chainable, intuitive methods (where, limit, orderby) replace messy string concatenation.
  • Secure by Default: Parameterized queries under the hood significantly reduce the risk of SQL injection attacks.
  • Modern & Type-Hinted: Fully type-hinted architecture provides excellent autocompletion and static analysis (Pylance/MyPy) in modern IDEs.
  • Lightweight: No bloated ORM overhead—just direct, efficient data access.

📦 Installation

pip install python-data-access

🚀 Quick Start

from easydb import pda

# 1. Connect to SQLite (or switch to MySQL/Flatfile just by changing this line)
db = pda.Database().db_sq3('app.sqlite')

# 2. Open or define a table
class Customers(pda.Table):
    _name: str = 'Customers'

    def ddl(self):
        return pda.DDL(self._name) \
            .integer('id', auto_increment=True) \
            .text('email', size=64, not_null=True, unique=True) \
            .integer('active')

customers = Customers()

# 3. Insert data securely
customers.insert({'email': 'hello@example.com', 'active': 1})

# 4. Query with the chainable builder
active_users = customers.where('active', 1).orderby('email').findall()

🎮 Running the Demo

If you want to see easydb in action before writing any code of your own, check out the included demo script!

The example directory contains a complete, working demo.py that sets up a local SQLite database, creates multiple linked tables (Customers, Orders, Products), inserts sample data, and runs through various query and update scenarios.

To run it, simply clone the repository change to the example dir and execute:

python3 demo.py

📖 API Documentation

🔌 1. Database Connections

Connect once, and the module handles the rest.

SQLite

db = pda.Database().db_sq3('/path/to/dbtest.sqlite')

MySQL

db = pda.Database().db_msq(host='localhost', database='dbtest', user='user', password='password')

Flatfile (Stores data directly in the OS filesystem—great for environments lacking SQL engines)

db = pda.Database().db_flat(datapath='/path/to', database='dbtest.flat')

🏗️ 2. Table Management & DDL

You can open existing tables or define their schema (DDL) directly in Python.

Open an existing table:

products = pda.Table('Products')

Define a table schema using the DDL Builder: Using keyword arguments makes your schema highly readable.

class Products(pda.Table):
    _name: str = 'Products'

    def ddl(self):
        return pda.DDL(self._name) \
            .integer('ProductId', auto_increment=True) \
            .text('Description', size=64, not_null=True, unique=True) \
            .real('Price') \
            .integer('Inactive')

products = Products()

Drop a table:

Products().drop()

💾 3. CRUD Operations

Insert:

result = products.insert({'Description': 'A Product Description', 'Price': 25})

Update:

# Update by primary key
products.update(1, {'Price': 19.99})

# Bulk update with conditions
products.where('Inactive', 1).where('Description', 'A%', 'like').updateall({'Price': 0})

Delete:

# Delete by primary key
products.delete(1)

# Bulk delete
products.where('Inactive', 1).deleteall()

🔍 4. Query Builder

The chainable query builder allows for expressive data retrieval.

# Find by Primary Key
item = products.find(1)

# Count records
total_active = products.where('Inactive', 0).count()

# Chain limits, offsets, and ordering
results = products.where('Inactive', 0) \
                  .orderby('Description') \
                  .limit(10) \
                  .offset(10) \
                  .findall()

# Get the single first matching row
first_match = products.where('Price', 100, '<').findfirst()

🛡️ 5. Database Transactions

Ensure data integrity by grouping operations into database-level transactions.

db.beginimmediate()

products.update(1, {'Price': 25.00})
order_details.where('ProductId', 1).updateall({'Price': 25.00})

db.committransaction()

📜 6. Custom SQL Execution

For complex joins or reports, load SQL from external files and execute it securely.

Let's assume you have a file production.sql:

SELECT production_date, description, quantity
FROM Production
LEFT JOIN Products ON Production.product_id = Products.product_id
ORDER BY production_date, description

You can load and filter this query directly through the API:

sql = products.getsql('production.sql')

# Apply query builder limits and filters to your raw SQL
result = products.limit(10).findall(sql)
result = products.where('Description', 'A%', 'like').findall(sql)

🔄 7. Utilities (CSV Import/Export)

products.import_csv('product_importdata.csv')
products.export_csv('product_exportdata.csv')

🧪 Testing & Benchmarks

Test your database engines individually:

python3 -m unittest discover tests test_pda_mysql.py
python3 -m unittest discover tests test_pda_sqlite.py
python3 -m unittest discover tests test_pda_flat.py

Run the built-in benchmarking tool to compare database performance:

python3 benchmarks.py --rows 1000

Metadata

Release files for python-data-access 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-data-access 1.4.0
File Size Uploaded Provenance Actions
python_data_access-1.4.0.tar.gz 23.0 kB Without provenance Details for python_data_access-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-data-access 1.4.0
File Interpreter ABI Platform Actions
python_data_access-1.4.0-py3-none-any.whl Python 3 none any Details for python_data_access-1.4.0-py3-none-any.whl

Total release size: 45.7 kB

Release files / python_data_access-1.4.0.tar.gz

Download URL python_data_access-1.4.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e58939df742ef1b731affa3daf90990afd70387f7cf894517adcb1fde19cf59d
BLAKE2b-256 checksum
How to use checksums
fe3666f521021e78bd0edfae486504d9401c12797132c830b74018b475639e99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / python_data_access-1.4.0-py3-none-any.whl

Download URL python_data_access-1.4.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99e090adee5aa3d3c1ddc8bbbce4eabf792f1649d0096a2e0a8631d6242d4dac
BLAKE2b-256 checksum
How to use checksums
3c6d727b149dd222b87e6d2b671b4abd7949a82e7c1b543929ceeabe2488d94f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for python-data-access 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page