A lightweight wrapper for the SQLite3 Python module.
Project description
nanoSQLite
nanoSQLite is a minimalistic SQLite wrapper tailored for those who feel JSON isn't quite right for data storage but
can't be bothered to dive deep into setting up a full-fledged ORM.
Sometimes, you just want a tiny step up without all the fuss. With less than 300 lines of Python code, it provides an uncomplicated interface for managing SQLite databases.
Despite its simplicity, nanoSQLite offers a robust set of functionalities that enable you to interact with SQLite databases seamlessly, without having to worry about managing cursors and connections manually.
It's designed to make working with SQLite in Python as straightforward and Pythonic as possible.
Ideal for small projects, prototypes, or when you just want a break from JSON but aren't ready for heavy ORM lifting.
Features
- Easy Setup: Create connections to SQLite databases with a single function call.
- Intuitive Interface: Insert, update, and delete data using a simple syntax.
- Quick Prototyping: Manage data efficiently with a few lines of code, perfect for rapid prototyping and basic projects.
- Flexible: Execute custom SQL statements using the underlying
sqlite3.Cursorandsqlite3.Connectionobjects. - Robust: The
sqlite3module is part of the Python standard library and has been extensively tested. - Pythonic: The nanoSQLite API is designed to be as Pythonic as possible, which makes it intuitive and easy to use.
- Pure Python: nanoSQLite is written with no dependencies.
- Lightweight: nanoSQLite is a single-file module with less than 300 lines of code.
- Open Source: nanoSQLite is distributed under the MIT license.
Examples
Most of database operations can be covered with the following examples:
-
Create a new SQLite database with a table:
from nanoSQLite import NanoSQLite db = NanoSQLite("people") db.create_table( "friends", { "id": "INTEGER PRIMARY KEY AUTOINCREMENT", "name": "TEXT", "age": "INTEGER", "height": "REAL", "is_cool": "BOOLEAN", }, )
-
Insert data:
db.insert("friends", {"name": "John", "age": 20, "height": 1.8, "is_cool": True}) db.insert("friends", {"name": "Jane", "height": 1.7, "is_cool": False}) db.insert("friends", {"name": "Bob"})
-
Update data:
db.update("friends", {"age": 21, "height": 1.9}, {"name": "John"}) db.update("friends", {"age": 5}, {"name": "Bob"})
-
Delete data:
db.delete("friends", {"name": "Jane"})
-
Select data:
db.select("friends", ["name", "age", "height", "is_cool"], {"name": "Bob"}) db.select_first("friends", ["name", "age", "height", "is_cool"], {"name": "Bob"}) db.select_all("friends")
When more advanced functionality is required, you can still execute custom SQL statements,
using the underlying sqlite3.Cursor and sqlite3.Connection objects:
data = [
("Monty Python Live at the Hollywood Bowl", 1982, 7.9),
("Monty Python's The Meaning of Life", 1983, 7.5),
("Monty Python's Life of Brian", 1979, 8.0),
]
db.cursor.executemany("INSERT INTO movie VALUES(?, ?, ?)", data)
db.connection.commit()
Installation
You can install nanoSQLite from PyPI:
pip install nanoSQLite
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanoSQLite-1.1.0.tar.gz.
File metadata
- Download URL: nanoSQLite-1.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4c4a89c9772da6c559ad4b0a5c6af3d6490250a32e2686635ed606c4489a2c5
|
|
| MD5 |
84d601cc258eb7290aa8d126991141a7
|
|
| BLAKE2b-256 |
b7cea4873f0b55e88ebc959b1622f3d4d47aa57136a89b1d86aacbc17ab48338
|
File details
Details for the file nanoSQLite-1.1.0-py3-none-any.whl.
File metadata
- Download URL: nanoSQLite-1.1.0-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
169da8718fdbfcef2a2f6b13ada6c6c19e4249ad9366f856b590a28412e3cefc
|
|
| MD5 |
b3727567e583ebdad120bf45930142e1
|
|
| BLAKE2b-256 |
08123a8956a3fcc4a098a0d2b8f0e032af7a621e4af1bc002fa89b26ea2f09a7
|