Skip to main content

A dict-like SQLite wrapper with APSW for instant persistence and memory caching

Project description

NanaSQLite

PyPI version Tests Python 3.9+ License: MIT

A dict-like SQLite wrapper with instant persistence and intelligent caching.

English | 日本語


English

🚀 Features

  • Dict-like Interface: Use familiar db["key"] = value syntax
  • Instant Persistence: All writes are immediately saved to SQLite
  • Smart Caching: Lazy load (on-access) or bulk load (all at once)
  • Nested Structures: Full support for nested dicts and lists (up to 30+ levels)
  • High Performance: WAL mode, mmap, and batch operations for maximum speed
  • Zero Configuration: Works out of the box with sensible defaults

📦 Installation

pip install nanasqlite

⚡ Quick Start

from nanasqlite import NanaSQLite

# Create or open a database
db = NanaSQLite("mydata.db")

# Use it like a dict
db["user"] = {"name": "Nana", "age": 20, "tags": ["admin", "active"]}
print(db["user"])  # {'name': 'Nana', 'age': 20, 'tags': ['admin', 'active']}

# Data persists automatically
db.close()

# Reopen later - data is still there!
db = NanaSQLite("mydata.db")
print(db["user"]["name"])  # 'Nana'

🔧 Advanced Usage

# Bulk load for faster repeated access
db = NanaSQLite("mydata.db", bulk_load=True)

# Batch operations for high-speed writes
db.batch_update({
    "key1": "value1",
    "key2": "value2",
    "key3": {"nested": "data"}
})

# Context manager support
with NanaSQLite("mydata.db") as db:
    db["temp"] = "value"

📚 Documentation

✨ New Features (v1.0.3rc3+)

Pydantic Support:

from pydantic import BaseModel

class User(BaseModel):
    name: str
    age: int

db.set_model("user", User(name="Nana", age=20))
user = db.get_model("user", User)

Direct SQL Execution:

# Execute custom SQL
cursor = db.execute("SELECT * FROM data WHERE key LIKE ?", ("user%",))
rows = db.fetch_all("SELECT key, value FROM data")

SQLite Wrapper Functions:

# Create tables and indexes easily
db.create_table("users", {
    "id": "INTEGER PRIMARY KEY",
    "name": "TEXT NOT NULL",
    "email": "TEXT UNIQUE"
})
db.create_index("idx_users_email", "users", ["email"])

# Simple queries
results = db.query(table_name="users", where="age > ?", parameters=(20,))

✨ Additional Features (v1.0.3rc4+)

22 new wrapper functions for comprehensive SQLite operations:

# Data operations
rowid = db.sql_insert("users", {"name": "Alice", "age": 25})
db.sql_update("users", {"age": 26}, "name = ?", ("Alice",))
db.upsert("users", {"id": 1, "name": "Alice", "age": 25})
total = db.count("users", "age >= ?", (18,))

# Query extensions (pagination, grouping)
page2 = db.query_with_pagination("users", limit=10, offset=10)
stats = db.query_with_pagination("orders", 
    columns=["user_id", "COUNT(*) as count"], group_by="user_id")

# Schema management
db.alter_table_add_column("users", "phone", "TEXT")
schema = db.get_table_schema("users")
db.drop_table("old_table", if_exists=True)

# Utilities & transactions
db.vacuum()  # Optimize database
with db.transaction():
    db.sql_insert("logs", {"message": "Event"})

日本語

🚀 特徴

  • dict風インターフェース: おなじみの db["key"] = value 構文で操作
  • 即時永続化: 書き込みは即座にSQLiteに保存
  • スマートキャッシュ: 遅延ロード(アクセス時)または一括ロード(起動時)
  • ネスト構造対応: 30階層以上のネストしたdict/listをサポート
  • 高性能: WALモード、mmap、バッチ操作で最高速度を実現
  • 設定不要: 合理的なデフォルト設定でそのまま動作

📦 インストール

pip install nanasqlite

⚡ クイックスタート

from nanasqlite import NanaSQLite

# データベースを作成または開く
db = NanaSQLite("mydata.db")

# dictのように使う
db["user"] = {"name": "Nana", "age": 20, "tags": ["admin", "active"]}
print(db["user"])  # {'name': 'Nana', 'age': 20, 'tags': ['admin', 'active']}

# データは自動的に永続化
db.close()

# 後で再度開いても、データはそのまま!
db = NanaSQLite("mydata.db")
print(db["user"]["name"])  # 'Nana'

🔧 高度な使い方

# 一括ロードで繰り返しアクセスを高速化
db = NanaSQLite("mydata.db", bulk_load=True)

# バッチ操作で高速書き込み
db.batch_update({
    "key1": "value1",
    "key2": "value2",
    "key3": {"nested": "data"}
})

# コンテキストマネージャ対応
with NanaSQLite("mydata.db") as db:
    db["temp"] = "value"

📚 ドキュメント

✨ 新機能 (v1.0.3rc3+)

Pydantic互換性:

from pydantic import BaseModel

class User(BaseModel):
    name: str
    age: int

db.set_model("user", User(name="Nana", age=20))
user = db.get_model("user", User)

直接SQL実行:

# カスタムSQLの実行
cursor = db.execute("SELECT * FROM data WHERE key LIKE ?", ("user%",))
rows = db.fetch_all("SELECT key, value FROM data")

SQLiteラッパー関数:

# テーブルとインデックスを簡単に作成
db.create_table("users", {
    "id": "INTEGER PRIMARY KEY",
    "name": "TEXT NOT NULL",
    "email": "TEXT UNIQUE"
})
db.create_index("idx_users_email", "users", ["email"])

# シンプルなクエリ
results = db.query(table_name="users", where="age > ?", parameters=(20,))

License

MIT License - see LICENSE for details.

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

nanasqlite-1.0.3rc4.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

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

nanasqlite-1.0.3rc4-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file nanasqlite-1.0.3rc4.tar.gz.

File metadata

  • Download URL: nanasqlite-1.0.3rc4.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanasqlite-1.0.3rc4.tar.gz
Algorithm Hash digest
SHA256 47cccc44ffac7b748fbef8a638de1cf57a8ff5a747470912165ac0b095df6fd7
MD5 df350a861002ff7fecd3daffa53a171c
BLAKE2b-256 2fc86be8b5b0fb9698817ccf579e4d08846f0d7ca0f76511e7cfcc063e7bae2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanasqlite-1.0.3rc4.tar.gz:

Publisher: publish.yml on disnana/NanaSQLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nanasqlite-1.0.3rc4-py3-none-any.whl.

File metadata

  • Download URL: nanasqlite-1.0.3rc4-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanasqlite-1.0.3rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 922feb149f8f47ccad4d7916c9a456a31ccc58c5c13c2831464a279063375727
MD5 0ff318e1d93fbc780eb2609e55726110
BLAKE2b-256 127c314d3112cbcecf72f2932db9d90b6cacb01592c5b3a6f7320d73eb07a615

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanasqlite-1.0.3rc4-py3-none-any.whl:

Publisher: publish.yml on disnana/NanaSQLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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