Skip to main content

Lightweight extensible ORM for SQLite

Project description

LiteModel

Install

pip install litemodel

Usage

Sync

# import Model
from litemodel.core import Model


# Define the Model
class Note(Model):
    title: str
    text: Optional[str]
    archived: bool = False

# Create the table in sqlite
Note.create_table()

# Create an instance
note = Note(title="Test", text="Just Testing")
note.save()

# Get the note
note = Note.find_by("title", "Test")

# Update the note
note.text = "Updating the note"
note.save()

Async

# import Model
from litemodel.async_core import Model


# Define the Model
class Note(Model):
    title: str
    text: Optional[str]
    archived: bool = False

# Create the table in sqlite
await Note.create_table()

# Create an instance
note = Note(title="Test", text="Just Testing")
await note.save()

# Get the note
note = await Note.find_by("title", "Test")

# Update the note
note.text = "Updating the note"
await note.save()

Example Project

I used this to build a CLI note app you can see here: https://github.com/psqnt/notes

look in the __main__.py file for some queries / instance creation and look in db.py for how to handle database creation / connection

Configuration

You can set some environment variables to control behavior

set where litemodel will look for your database

export DATABASE_PATH=/path/to/my/db/sqlite.db

set to debug mode

export LITEMODEL_DEBUG=True

Note

This was written fairly quickly and is lacking some functionality that I hopefully can get to soon. However, its a very small project so should be easy to update if you want to fork. Also its easily extensible to make better queries when needed

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

litemodel-0.1.11.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

litemodel-0.1.11-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file litemodel-0.1.11.tar.gz.

File metadata

  • Download URL: litemodel-0.1.11.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.13

File hashes

Hashes for litemodel-0.1.11.tar.gz
Algorithm Hash digest
SHA256 9d33df317dd392ca32b982329586cc3ff80a420928537ffdd6ee37ee1d42c9f5
MD5 07db92442b2cacb008a2a456fda56733
BLAKE2b-256 c6048125a324f820d2fdad34fbadfda14147041202bce5bb19e64a49c2a8c574

See more details on using hashes here.

File details

Details for the file litemodel-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for litemodel-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 a463bad1568e03c89b2760ba136472d463797c3b67ba27eacc377e3d5b78fbd9
MD5 c706cd7aa1c0abbc198a755e79c155d0
BLAKE2b-256 7f513aaa55b9ab6a814a53dbdcd13d95d2adfa3af02bd0e10e614f6710ce2b71

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