Skip to main content

PyPI version License: AGPL v3

dpyb

A simple, dependency-free, file-based Python database.

dpyb is a lightweight database that stores all its data in a single Python-readable file with the .dpyb.py extension. Every table is a plain Python dictionary, so you can read, inspect, and even version-control your database with Git.

  • Zero dependencies — only the Python standard library
  • Human-readable format — data is stored as plain Python dicts
  • Automatic backups — every write operation creates a timestamped backup (can be disabled)
  • Simple API — 13 functions, no classes to learn
  • Consistent tables — rows and columns never go out of sync

Requirements

  • Python 3.12 or newer

Installation

pip install dpyb

Quick start

import dpyb

# Create a new database
dpyb.CreateDataBase("mydb")

# Add a table
dpyb.AddTableToDataBase("mydb", "users")

# Add 5 empty rows and 2 extra columns
dpyb.AddRow("mydb", "users", 5)      # 6 rows total
dpyb.AddColumn("mydb", "users", 2)   # 3 columns total

# Fill some cells
dpyb.WriteData("mydb", "users", 1, 1, "Ali")
dpyb.WriteData("mydb", "users", 1, 2, 25)
dpyb.WriteData("mydb", "users", 1, 3, "Tehran")

# Read a cell
print(dpyb.ReadData("mydb", "users", 1, 1))   # "Ali"

The file mydb.dpyb.py will look like this:

# a d-py-b database file, DO NOT EDIT THIS FILE
# d-py-b, a simple python database by darkstarshine2011

# ---

users = {
    1: {1: 'Ali', 2: 25, 3: 'Tehran'},
    2: {1: '', 2: '', 3: ''},
    3: {1: '', 2: '', 3: ''},
    4: {1: '', 2: '', 3: ''},
    5: {1: '', 2: '', 3: ''},
    6: {1: '', 2: '', 3: ''},
}

Data model

A dpyb database is a set of tables. Each table is a dictionary:

Table = {
    RowID: { ColumnID: Value, ColumnID: Value, ... },
    RowID: { ColumnID: Value, ColumnID: Value, ... },
}

Example:

users = {
    1: {1: "Ali",  2: 25, 3: "Tehran"},
    2: {1: "Sara", 2: 30, 3: "Shiraz"},
    3: {1: "Reza", 2: 40, 3: "Mashhad"},
}
  • Row IDs and Column IDs are integers.
  • Values can be any Python literal: str, int, float, bool, None, list, dict, tuple.

How AddRow and AddColumn work

  • AddRow(db, table, N) adds N new rows. Each new row inherits every column that already exists in the table, filled with "".
  • AddColumn(db, table, N) adds N new columns to every row in the table, filled with "".
  • A newly created table starts with 1 row and 1 column.

This means you never have to worry about rows and columns getting out of sync. Every row always has exactly the same set of columns.


API Reference

Note: All write operations (AddTableToDataBase, AddRow, AddColumn, WriteData, DeleteRow, DeleteColumn, DeleteTable) accept an optional Backup parameter. It defaults to True. Set it to False to skip creating a backup (useful for bulk operations).

GetDataBaseName(DataBaseFile)

Normalizes a database filename. Adds the .dpyb.py extension if missing.

dpyb.GetDataBaseName("mydb")        # "mydb.dpyb.py"
dpyb.GetDataBaseName("mydb.dpyb")   # "mydb.dpyb.py"
dpyb.GetDataBaseName("mydb.py")     # "mydb.dpyb.py"

CreateDataBase(DataBaseFile)

Creates a new, empty database file. Overwrites the file if it already exists.

dpyb.CreateDataBase("mydb")

CreateBackup(DataBaseFile)

Creates a timestamped backup of the database in the Backup/ folder.

This is called automatically by every write operation (unless Backup=False), so you rarely need to call it manually.

AddTableToDataBase(DataBaseFile, TableName, Backup=True)

Adds a new table to the database. The table starts with 1 row and 1 column, both empty. Does nothing if the table already exists.

dpyb.AddTableToDataBase("mydb", "users")

AddRow(DataBaseFile, TableName, Rows=1, Backup=True)

Adds Rows new rows to the table. Each new row inherits all existing columns, filled with "". Default is 1 row.

dpyb.AddRow("mydb", "users")      # 1 new row
dpyb.AddRow("mydb", "users", 5)   # 5 new rows

AddColumn(DataBaseFile, TableName, Columns=1, Backup=True)

Adds Columns new columns to every row of the table, filled with "". Default is 1 column.

dpyb.AddColumn("mydb", "users")      # 1 new column
dpyb.AddColumn("mydb", "users", 3)   # 3 new columns

ReadData(DataBaseFile, TableName, Row, Column)

Returns the value of a single cell.

Name = dpyb.ReadData("mydb", "users", 1, 1)   # "Ali"

WriteData(DataBaseFile, TableName, Row, Column, Value, Backup=True)

Writes a value into a single cell.

dpyb.WriteData("mydb", "users", 1, 2, 26)

DeleteRow(DataBaseFile, TableName, Row, Backup=True)

Deletes a row from the table.

dpyb.DeleteRow("mydb", "users", 2)

DeleteColumn(DataBaseFile, TableName, Column, Backup=True)

Deletes a column from every row of the table.

dpyb.DeleteColumn("mydb", "users", 3)

DeleteTable(DataBaseFile, TableName, Backup=True)

Deletes an entire table from the database.

dpyb.DeleteTable("mydb", "users")

ListTables(DataBaseFile)

Returns a list of all table names.

dpyb.ListTables("mydb")   # ["users", "posts"]

GetTable(DataBaseFile, TableName)

Returns the entire table as a Python dictionary.

Users = dpyb.GetTable("mydb", "users")

Examples

The examples/ folder contains ready-to-run scripts, from a basic hello-world to a small inventory system.

# File What it shows
01 Getting started Create a database, add a table, write and read a cell
02 Adding rows and columns How AddRow and AddColumn keep tables consistent
03 Reading and writing cells Fill a small table cell by cell
04 Iterating over a table Loop through every row and every cell
05 Multiple tables One database, many independent tables
06 Deleting Delete rows, columns, and full tables
07 Filling from a list Populate a table from a Python list
08 Simple todo list A tiny command-line app with state
09 Searching and filtering Find rows matching a condition
10 Contact book Add / find / delete a contact
11 Statistics on a table Sum, average, min, max with plain Python
12 Copying a table Duplicate a table inside the same database
13 Nested data Store lists and dicts inside cells
14 Inventory system A small shop inventory with sell / restock
15 Complete workflow End-to-end tour of the entire API
16 Disabling backups Use Backup=False for bulk operations

Backups

By default, every write operation creates a timestamped backup inside a Backup/ folder next to your script.

Backup/
├── 20261005_120000_123456.dpyb.py.backup
├── 20261005_120015_654321.dpyb.py.backup
└── ...

Disabling backups

If you are doing a large number of writes at once (e.g., filling a big table in a loop), creating a backup for every single write can slow things down and flood your hard drive with thousands of files. You can disable backups for individual calls by passing Backup=False:

# Do one backup manually before the bulk operation
dpyb.CreateBackup("mydb")

# Add 100 rows without creating 100 backup files
for i in range(100):
    dpyb.AddRow("mydb", "users", 1, Backup=False)

Read operations (ReadData, GetTable, ListTables) do not create backups.


Notes

  • Database files use the .dpyb.py extension and should not be edited by hand. They are valid Python files, but a wrong edit can break the parser.
  • dpyb has zero external dependencies.
  • Not designed for concurrent writes. If multiple processes write to the same database at the same time, data loss may occur.
  • Not designed for large datasets. Every write reads and rewrites the entire file.

License

This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). See the LICENSE file for the full text.


Author

Made by darkstarshine2011


Credits

  • Library code — darkstarshine2011
  • Examples — written by DeepSeek

Metadata

Release files for dpyb 0.1.8

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

Source distribution (sdist)

Source distribution for dpyb 0.1.8
File Size Uploaded Provenance Actions
dpyb-0.1.8.tar.gz 18.1 kB Without provenance Details for dpyb-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dpyb 0.1.8
File Interpreter ABI Platform Actions
dpyb-0.1.8-py3-none-any.whl Python 3 none any Details for dpyb-0.1.8-py3-none-any.whl

Total release size: 36.5 kB

Release files / dpyb-0.1.8.tar.gz

Download URL dpyb-0.1.8.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
97ed9e4d6713362a0c47baff1198512250067e1aeb4dba3bd21f57c2f273f3d5
BLAKE2b-256 checksum
How to use checksums
134e37e252dd6f3f36a081553743a68151735920127d49d6a415da74d269e0c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / dpyb-0.1.8-py3-none-any.whl

Download URL dpyb-0.1.8-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b41aa6d01531ff04c7402ab06cbbb6c0b8d74a4fd0a76280c11b967f6bc7f2bf
BLAKE2b-256 checksum
How to use checksums
e41aee6f5011730b034e660c0d1fcea5853d1d8514370907a2887d348b80f2e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for dpyb 0.1.8

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