Skip to main content

Unified database interface for MySQL, PostgreSQL, and MongoDB

Project description


⚡ pyflashdb

Stop writing database code three times.

PyPI Python License: MIT MySQL PostgreSQL MongoDB



What is pyflashdb?

pyflashdb is a Python library that lets you talk to MySQL, PostgreSQL, and MongoDB using the exact same code.

You write one line. It works on all three databases. No SQL knowledge required. No driver switching. No boilerplate.

from flash import FlashDB

flash = FlashDB("mysql", config)   # change to "postgres" or "mongodb" — nothing else changes

flash.add("users", {"name": "Alice", "age": 25})      # insert
flash.where("users", {"age": {">": 18}})              # filter
flash.update("users", {"name": "Alice"}, {"age": 26}) # update
flash.delete("users", {"name": "Alice"})              # delete

That's it. Same four lines work on MySQL, PostgreSQL, and MongoDB.


The Problem It Solves

Most projects start with one database and grow to need another. Or your team uses MySQL locally but PostgreSQL in production. Or you want MongoDB for one feature and SQL for another.

Every time you switch databases, you rewrite your query code — because each database has a completely different API.

Without pyflashdb — three different APIs to learn and maintain:

# MySQL
cursor.execute("INSERT INTO users (name, age) VALUES (%s, %s)", ("Alice", 25))
conn.commit()

# PostgreSQL — different driver, slightly different syntax
cursor.execute('INSERT INTO "users" (name, age) VALUES (%s, %s) RETURNING id', ("Alice", 25))

# MongoDB — completely different world
db["users"].insert_one({"name": "Alice", "age": 25})

With pyflashdb — one line, any database:

flash.add("users", {"name": "Alice", "age": 25})

Switch your database by changing one word. Your application code stays exactly the same.


Install

# Pick the database you use
pip install pyflashdb[mysql]      # MySQL
pip install pyflashdb[postgres]   # PostgreSQL
pip install pyflashdb[mongodb]    # MongoDB
pip install pyflashdb[all]        # All three

Quick Example — A Complete User System in 20 Lines

from flash import FlashDB

# Connect — swap "mysql" for "postgres" or "mongodb" to change databases
flash = FlashDB("mysql", {
    "host":     "localhost",
    "user":     "root",
    "password": "your_password",
    "database": "myapp"
})

# Create the table
flash.create_table("users", {
    "id":    "int",
    "name":  "str",
    "email": "str",
    "age":   "int",
})

# Insert
flash.add("users", {"name": "Alice", "email": "alice@example.com", "age": 25})
flash.add("users", {"name": "Bob",   "email": "bob@example.com",   "age": 17})

# Read
all_users  = flash.all("users")                          # everyone
adults     = flash.where("users", {"age": {">": 18}})   # filtered
one_user   = flash.find_one("users", {"name": "Alice"}) # single record
page       = flash.paginate("users", page=1, size=10)   # paginated

# Update
flash.update("users", {"name": "Alice"}, {"age": 26})

# Delete
flash.delete("users", {"name": "Bob"})

flash.close()

Core Features

Everything you need for database work

Feature What it does
add() Insert one record, returns the new ID
bulk_insert() Insert many records in one call
all() Fetch every record from a table
where() Fetch records matching a filter
select() Full query — filter, sort, limit, offset, specific fields
find_one() Get the first match, or None
count() Count records without fetching them
paginate() Built-in pagination with total count
update() Update matching records
delete() Delete matching records
create_table() Create a table or collection
drop_table() Drop a table or collection
truncate() Clear all rows, keep the structure
raw() Run a raw SQL query or MongoDB command
begin / commit / rollback Full transaction support

Smart filter syntax — write once, works everywhere

flash.where("users", {"age": {">": 18}})
flash.where("users", {"age": {">=": 18, "<=": 65}})
flash.where("users", {"role": {"in": ["admin", "mod"]}})
flash.where("users", {"email": {"like": "%@gmail.com"}})
flash.where("users", {"status": {"!=": "banned"}})

Trigger hooks — observe any operation

@flash.before_insert("users")
def validate(data):
    if not data.get("email"):
        raise ValueError("Email is required")

@flash.after_insert("users")
def on_created(data, result):
    print(f"New user created — ID: {result}")

@flash.after_delete("orders")
def on_deleted(filters, count):
    print(f"Deleted {count} order(s)")

Transactions — atomic operations

flash.begin()
try:
    flash.update("accounts", {"user_id": 1}, {"balance": 400})
    flash.update("accounts", {"user_id": 2}, {"balance": 600})
    flash.commit()
except Exception as e:
    flash.rollback()

How pyflashdb Compares

pyflashdb SQLAlchemy Django ORM Raw drivers
Works on MySQL
Works on PostgreSQL
Works on MongoDB
Same API across all DBs

Links


Documentation

📄 Full Documentation (PDF)

pyflashdb v1.0.4 · MIT License · Python 3.8+

One API. Any database. Zero boilerplate.

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

pyflashdb-1.0.4.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

pyflashdb-1.0.4-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file pyflashdb-1.0.4.tar.gz.

File metadata

  • Download URL: pyflashdb-1.0.4.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyflashdb-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b6b3d5559297a13ff7f07487a25913ea549d87bda7e7c1226db96b1d09e61038
MD5 f74fb815796eaa54c00db728ef9e2418
BLAKE2b-256 68dc12058f68befc768c53f5ab72353bf86d8d62416b630e6c8db14aa70580d5

See more details on using hashes here.

File details

Details for the file pyflashdb-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyflashdb-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pyflashdb-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e68b7af745a524d07dda970f920759897391cab81d11ad3c5c235f3d0820d0cb
MD5 ca629631c6236cbc682647360588b7d0
BLAKE2b-256 96b9976f2549ee56003d8e24d4b71f85720d7edc0f2c2e5df021ac1c92b83e9c

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