Skip to main content

FineSQL ORM

Finesql Purpose Python License

FineSQL is a lightweight Python ORM built on top of sqlite3 for educational purposes.
It provides simple table definitions, CRUD operations, and foreign key support while keeping the codebase minimal and easy to understand.


Installation

No external dependencies required — only Python standard library.

git clone https://github.com/goldendevuz/finesql
cd finesql

Quick Start

1. Define Tables

from finesql import Database, Table, Column, ForeignKey


class User(Table):
    username = Column(str)
    age = Column(int)


class Post(Table):
    title = Column(str)
    body = Column(str)
    author = ForeignKey(User)

2. Initialize Database

db = Database("app.db")

db.create(User)
db.create(Post)

3. Create Records

user = User(username="Alice", age=25)
db.save(user)

post = Post(title="Hello World", body="This is my first post", author=user)
db.save(post)

4. Query Records

# Get all users
users = db.all(User)
for u in users:
    print(u.id, u.username, u.age)

# Get by id
alice = db.get(User, id=1)
print(alice.username)

# Filter by field (LIKE search)
maybe_alice = db.get_by_field(User, field_name="username", value="Alice")
print(maybe_alice.username)

# Custom select (dict result)
result = db.get_user(User, field_name="username", value="Alice", return_fields=["id", "age"])
print(result)  # {'id': 1, 'age': 25}

5. Update Records

alice = db.get(User, id=1)
alice.age = 26
db.update(alice)

6. Delete Records

db.delete(User, id=1)

Relationships

Foreign keys can be defined using ForeignKey.
For example, Post has an author = ForeignKey(User).
When fetching posts, the related User instance will be automatically resolved:

post = db.get(Post, id=1)
print(post.author.username)

Full Example

Here’s the complete example code in one file:

from finesql import Database, Table, Column, ForeignKey


# Define models
class User(Table):
    username = Column(str)
    age = Column(int)


class Post(Table):
    title = Column(str)
    body = Column(str)
    author = ForeignKey(User)


# Initialize database
db = Database("app.db")
db.create(User)
db.create(Post)

# Create records
user = User(username="Alice", age=25)
db.save(user)
post = Post(title="Hello World", body="This is my first post", author=user)
db.save(post)

# Query records
print("All users:", db.all(User))
print("User by id:", db.get(User, id=1).username)

# Update
alice = db.get(User, id=1)
alice.age = 26
db.update(alice)

# Relationship
post = db.get(Post, id=1)
print("Post author:", post.author.username)

# Delete
db.delete(User, id=1)

API Reference

Database

  • create(table) → Creates a table.
  • save(instance) → Inserts a record.
  • all(table) → Returns all records.
  • get(table, id) → Get record by id.
  • get_by_field(table, field_name, value) → LIKE search by field.
  • get_user(table, field_name, value, return_fields) → Dict select with custom fields.
  • update(instance) → Updates a record.
  • delete(table, id) → Deletes a record.

Table

  • Base class for all models.
  • Automatically provides id field.
  • Column and ForeignKey definitions supported.

Column

  • Define a typed column (int, str, float, bool, bytes).

ForeignKey

  • Define foreign key to another table.

Roadmap

  • Migrations
  • Query builder
  • Async support
  • Type checking with mypy

License

MIT © 2025 Abdulmajid Yunus


Metadata

Release files for finesql 0.0.2

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

Source distribution (sdist)

Source distribution for finesql 0.0.2
File Size Uploaded
finesql-0.0.2.tar.gz 6.4 kB Details

Built distribution (wheel)

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

Total release size: 12.8 kB

Release files / finesql-0.0.2.tar.gz

Download URL finesql-0.0.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d43bad312eaba39770e49e4572b51d3cdc32be0c541e39668242396b5fd0ab07
BLAKE2b-256 checksum
How to use checksums
eebd124da828ade4632cf294e03119026b6766a087bdc7768960c13caba2ccb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / finesql-0.0.2-py3-none-any.whl

Download URL finesql-0.0.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20bc1fbe7df12d4aa872ebd55b79a5c9743a8427d64ad426055a73d572c2cfda
BLAKE2b-256 checksum
How to use checksums
354777f221beaa9c11df799a55cf78c2e8c084df38139c59e0a5e38c567a2258
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3
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