Skip to main content

FineSQL is a library for interacting with SQLite database from Python code, with Python objects.

Project description

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


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

finesql-0.1.3.4.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

finesql-0.1.3.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file finesql-0.1.3.4.tar.gz.

File metadata

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

File hashes

Hashes for finesql-0.1.3.4.tar.gz
Algorithm Hash digest
SHA256 ec1ff0a40a53d4addfd76025e14a4aeafb956a7936ba2a1bb70a6be7314713e1
MD5 f3f954833d895e39389849c74b568055
BLAKE2b-256 51c3bd5c238a05d06dba6e3d9b11ca1412efb33c5f00af6aa0a8653656d36f28

See more details on using hashes here.

File details

Details for the file finesql-0.1.3.4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for finesql-0.1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 426d9e63615c12b45d6b89db3a50461a0f8c2c7ca792185c874c58ced661a795
MD5 349ef4a072271e1826e8b67161a064fa
BLAKE2b-256 ba57f24ccd8a1001c44e396f42bb5ba38015627e24a4ef0621a7a04651b960e6

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