RpRelPyDBRelational Python

Documentation

0. Start Here

A guided entry point for new developers who want to understand how to use RelPyDB.

Start here

RelPyDB is easiest to learn as a small relational database object inside Python. The basic flow is simple: create a database object, define schema, insert rows, query, export, and optionally save the object.

  1. Create a RelPy() object.
  2. Create tables with create_table.
  3. Add columns with add_column.
  4. Insert one row with insert or many rows with insert_many.
  5. Query with db.query(...), where, select, joins, and grouping.
  6. Export with to_list, to_json, to_pandas, to_numpy, to_sql, or to_ddl.
  7. Save and load with save and RelPy.load.

The mental model

Think of RelPyDB as a Python object that contains relational tables. It is not a server and it is not a full SQL engine. You work with normal Python code, but the data has relational structure.

RelPy object
  ├── schema
  │   ├── tables
  │   ├── columns
  │   ├── primary keys
  │   └── foreign keys
  ├── data rows
  ├── indexes
  ├── views
  ├── query builder
  └── exports / persistence

The first thing to read

GoalRead thisWhy
I want to run code now5-Minute QuickstartSmall complete script with insert, then insert_many, query, output, save and load.
I want to build a realistic modelFull TutorialUsers, orders, support tickets, joins and grouping.
I have a specific taskCommon RecipesCopyable patterns for common use cases.
I want every functionFunction ReferenceInputs, outputs, imports, examples and notes.

Small complete example

from relpy import RelPy, AutoNumber, col

db = RelPy()

db.create_table("users")
db.add_column("users", "id", AutoNumber, is_primary_key=True)
db.add_column("users", "name", str, nullable=False)
db.add_column("users", "status", str, nullable=False, default="active")

db.insert("users", {"name": "Alice"})

db.insert_many("users", [
    {"name": "Bob", "status": "inactive"},
    {"name": "Carol"},
])

active_users = (
    db.query("users")
      .where(col("status") == "active")
      .select("id", "name")
      .to_list()
)

print(active_users)
Output
[{"id": 1, "name": "Alice"}, {"id": 3, "name": "Carol"}]