Getting Started¶
This guide walks you through installing Lythonic and creating your first database schema.
Installation¶
Install with pip:
Or with uv:
Define Your First Model¶
Create a Python file with your schema definition:
from pydantic import Field
from lythonic.state import DbModel, Schema
class Task(DbModel["Task"]):
task_id: int = Field(default=-1, description="(PK)")
title: str = Field(description="Task title")
completed: bool = Field(default=False)
SCHEMA = Schema([Task])
Key points:
- Inherit from
DbModel["YourClassName"](the string must match the class name) - Mark primary keys with
(PK)in the field description - Use
default=-1for auto-increment primary keys
Create the Database¶
This generates and executes:
Insert and Query Data¶
from lythonic.state import open_sqlite_db
with open_sqlite_db("tasks.db") as conn:
# Create a task
task = Task(title="Learn Lythonic")
task.save(conn) # Inserts and sets task_id
print(f"Created task with id: {task.task_id}")
# Query all tasks
all_tasks = Task.select(conn)
# Query with filter
incomplete = Task.select(conn, completed=False)
# Load by ID
loaded = Task.load_by_id(conn, task.task_id)
conn.commit()
Next Steps¶
- Your First Schema Tutorial - Deeper dive into schema definition
- CRUD Operations - All database operations explained
- API Reference - Complete API documentation