Observed since 20 Oct, 21:01 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Core SQLite ORM with separate educational modules
# af_db_teach
A simple, educational ORM for SQLite in Python.
This package allows you to work with an SQLite database without writing raw SQL queries.
Designed for small projects and learning ORM concepts.
## Features
- Define models using Python classes and simple attributes
- Automatic CRUD operations (Create, Read, Update, Delete)
- Automatic table management (create, update schema, drop)
- Support for default data (`_default_data`)
- Helper methods like search, borrow/return (in the library example)
- Export all tables and data as a dictionary with `db_deeep_interface`
## Installation
```bash
pip install af_db_teach
Note: This package will be published on PyPI soon. You can also use it directly from the GitHub repository.
from af_db_teach import Model
class Product(Model):
_primary_key = "id"
id = 0
name = ""
price = 0.0
in_stock = 1
productint, float, str).# Connect and create the table
db = Product("shop.db")
# Insert a row
new_id = db.insert_one(name="Python Book", price=25000, in_stock=1)
# Get all records
all_products = db.get_all()
# Get a single record by primary key
product = db.get_one(1)
# Update a record
db.update(1, price=27000)
# Delete a record
db.delete(1)
# Drop the entire table
db.delete_table()
You can define _default_data in your model class to insert initial records:
class Category(Model):
id = 0
title = ""
_default_data = [
(1, "Electronics"),
(2, "Books"),
(3, "Clothing"),
]
Note: The order of values must match the order of fields returned by
table_fields().
| Method | Description |
|---|---|
insert_one(**kwargs) | Insert a new row. Returns lastrowid. |
get_all(where="", params=()) | Get all rows (optional WHERE clause). |
get_one(row_id) | Get a single row by primary key. |
update(row_id, **kwargs) | Update specified fields. |
delete(row_id) | Delete a row by primary key. |
delete_table(table_name=None) | Drop the entire table. |
db_deeep_interface() | Return a dictionary of all tables and their contents. |
The file library_orm_demo.py provides a practical library system example:
from af_db_teach import Model
from datetime import date
class Book(Model):
_primary_key = "id"
id = 0
title = ""
author = ""
year = 2000
is_available = 1
def borrow(self, book_id):
book = self.get_one(book_id)
if book and book['is_available'] == 1:
return self.update(book_id, is_available=0)
return False
def return_book(self, book_id):
book = self.get_one(book_id)
if book and book['is_available'] == 0:
return self.update(book_id, is_available=1)
return False
# Usage
book_db = Book("library.db")
book_db.insert_one(title="Thus Spoke Zarathustra", author="Nietzsche", year=1885)
book_db.borrow(1) # borrow the book
book_db.return_book(1) # return it
Run the full demo:
python library_orm_demo.py
The Keywords class contains a list ignores_table_name_list. If a table name is in this list, create_table will not create it. You can extend this list:
from af_db_teach import Keywords
Keywords.ignores_table_name_list.append("my_temp_table")
TableBaseIf you need a model without direct database connection (just the table structure), you can inherit from TableBase.
db = Model("my_database.db")
If the database file does not exist, it will be created.
This project is released under the MIT License.
Abbas Faramarzi
Email
GitHub Repository
af_db_teach – A simple tool for learning and using ORM in small Python projects.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.0 | 10 Jun 2026 | 0 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 21:01 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:603d28fbb71222341b56b0d0dffe0cc9d19fda2768a387fa55df54523dc564c7