Dante is zero-setup, easy to use document store (NoSQL database) for Python. It's ideal for exploratory programming, prototyping, internal tools and small, simple projects.
Dante can store Python dictionaries or Pydantic models, supports both sync and async mode, and is based on SQLite.
Dante does not support SQL, relations, ACID, aggregation, replication and is emphatically not web-scale. If you need those features, you should choose another database or ORM engine.
-
Install via PyPI:
pip install dante-db
-
Use it with Python dictionaries (example):
from dante import Dante # Create 'mydatabase.db' in current directory and open it # (you can omit the database name to create a temporary in-memory database.) db = Dante("mydatabase.db") # Use 'mycollection' collection (also known as a "table") collection = db["mycollection"] # Insert a dictionary to the database data = {"name": "Dante", "text": "Hello World!"} collection.insert(data) # Find a dictionary with the specified attribute(s) result = collection.find_one(name="Dante") print(result["text"]) new_data = {"name": "Virgil", "text": "Hello World!"} collection.update(new_data, name="Dante")
Under the hood, Dante stores each dictionary in a JSON-encoded TEXT column in a table (one per collection) in the SQLite database.
Dante works great with Pydantic.
Using the same API as with the plain Python objects, you can insert, query and delete Pydantic models (example):
from dante import Dante
from pydantic import BaseModel
class Message(BaseModel):
name: str
text: str
# Open the database and get the collection for messages
db = Dante("mydatabase.db")
collection = db[Message]
# Insert a model to the database
obj = Message(name="Dante", text="Hello world!")
collection.insert(obj)
# Find a model with the specified attribute(s)
result = collection.find_one(name="Dante")
print(result.text)
# Find a model in the collection with the attribute name=Dante
# and update (overwrite) it with the new model data
result.name = "Virgil"
collection.update(result, name="Dante")
Dante supports async usage with the identical API, both for plain Python objects and Pydantic models (example):
from asyncio import run
from dante import AsyncDante
async def main():
db = AsyncDante("mydatabase.db")
collection = await db["mycollection"]
data = {"name": "Dante", "text": "Hello World!"}
await collection.insert(data)
result = await collection.find_one(name="Dante")
print(result["text"])
new_data = {"name": "Virgil", "text": "Hello World!"}
await collection.update(new_data, name="Dante")
await db.close()
run(main())
Check out the command-line ToDo app, a simple FastAPI CRUD app, and the other examples in the examples directory.
Detailed guide on how to develop, test and publish Dante is available in the Developer documentation.
Copyright (c) 2024. Senko Rasic
This software is licensed under the MIT license. See the LICENSE file for details.