Dante,一个由SQLite支持的Python文档存储
项目描述
Dante,一个由SQLite支持的Python文档存储
Dante是一个零配置、易于使用的Python文档存储(NoSQL数据库)。它非常适合探索性编程、原型设计、内部工具和简单的小型项目。
Dante可以存储Python字典或Pydantic模型,支持同步和异步模式,基于SQLite。
Dante不支持SQL、关系、ACID、聚合、复制,并且明确不是Web规模的。如果您需要这些功能,应选择其他数据库或ORM引擎。
快速入门
-
通过PyPI安装
pip install dante-db
-
使用Python字典(示例)
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")
在内部,Dante将每个字典存储在SQLite数据库中的一个表中(每个集合一个表),该表有一个JSON编码的TEXT列。
与Pydantic一起使用
Dante非常适合与Pydantic一起使用。
使用与纯Python对象相同的API,您可以对Pydantic模型进行插入、查询和删除(示例)
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
Dante支持使用相同的API进行异步使用,无论是纯Python对象还是Pydantic模型(示例)
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())
示例
查看命令行ToDo应用、简单的FastAPI CRUD应用以及示例目录中的其他示例。
开发
有关如何开发、测试和发布Dante的详细指南可在开发者文档中找到。
许可证(MIT)
版权(c)2024. Senko Rasic
特此授予任何获得此软件和相关文档副本(“软件”)的人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供的人这样做,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、特定用途适用性和非侵权的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任源于合同行为、侵权或其他行为,也不论这些责任是否与软件、使用或其他与软件相关的行为有关。
项目详情
下载文件
下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分布
构建分布
dante_db-0.1.1.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 4da0c604ed391a51f00fb472ce38835f61fee8fbbc2585b6005c1488a87782a9 |
|
MD5 | b1aae3e10f2f65d3641def4334c91fad |
|
BLAKE2b-256 | 20b301d9d7d0f44e7d952b73995394b8c13cbac4c8a0cedd42320f0fdfac96f9 |
dante_db-0.1.1-py3-none-any.whl的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 275554c8992e45dc029a4e6bc9dfa625bc8eff17c21e5f7bbedda34c76b15998 |
|
MD5 | 0dd7dd74efa656a48d53b0cf2c4438bb |
|
BLAKE2b-256 | bf1cd2877836a18c4ce1c7d25c3460110c9041389ba2d89f2d830d1c8253bd99 |