Skip to main content

Mango

Mango

🥭 带有类型提示的 Python 异步 MongoDB 对象文档映射器

license pypi python

查看演示 · 错误报告 · 功能请求

简体中文 · English · 日本語

🔖 目录

目录

📖 简介

Mango 是一个带有类型提示的 Python 异步 MongoDB 对象文档映射器(ODM),它构建在 Motor 和 Pydantic 之上。

Mango 使得数据建模和查询变得非常容易,帮助您关注应用程序中真正重要的部分。

✨ 核心特性:

  • 完善的类型标注:利用静态分析来减少运行时问题
  • 简洁流畅的 API:更易于学习和使用,提高开发效率
  • 优雅的编辑器支持:自动完成无处不在,从对象创建到查询结果

[⬆回到顶部]

🚀 安装

PIP

pip install mango-odm

Poetry

poetry add mango-odm

[⬆回到顶部]

🌟 示例

import asyncio

from mango import Document, EmbeddedDocument, Field, Mango


# 嵌入式文档
class Author(EmbeddedDocument):
    name: str
    profile: str | None = None


# Mango 文档模型
class Book(Document):
    name: str = Field(primary_key=True)  # 将字段设置为主键,如果不显式指定主键,则会自动创建 id 字段作为主键
    summary: str | None = None
    author: Author  # 嵌入文档
    price: int = Field(index=True)  # 为字段添加索引


async def main():
    # 初始化 Mango,它会创建连接并初始化文档模型,你可以传入 db 或者 uri 参数来指定连接
    await Mango.init()

    # 像 pydantic 的模型一样使用
    book = Book(name="book", author=Author(name="author"), price=10)
    # 将它插入到数据库中
    await book.save()

    # Mango 提供了丰富的查询语言,允许您使用 Python 表达式来查询
    if book := await Book.find(Book.price <= 20, Book.author.name == "author").get():
        # 更新文档的 summary 字段
        book.summary = "summary"
        await book.update()


if __name__ == "__main__":
    asyncio.run(main())

[⬆回到顶部]

🤝 贡献

想为这个项目做出一份贡献吗?点击这里阅读并了解如何贡献。

🎉 鸣谢

感谢以下开发者对该项目做出的贡献:

[⬆回到顶部]

💖 支持

喜欢这个项目?请点亮 star 并分享它!

[⬆回到顶部]

📝 许可证

在 MIT 许可证下分发。请参阅 LICENSE 以获取更多信息。

[⬆回到顶部]

Release files for mango-odm 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mango-odm 0.4.1
File Size Uploaded
mango_odm-0.4.1.tar.gz 21.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mango-odm 0.4.1
File Interpreter ABI Platform
mango_odm-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.2 kB

Release files / mango_odm-0.4.1.tar.gz

Download URL mango_odm-0.4.1.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
abf69848496b6bcc7c69ad01963d79d20f1f955f8c8751bd0a9147655619291e
BLAKE2b-256 checksum
How to use checksums
70e24d17a46b284e0bbf90a276213f5a1e63351e0b01ca12b9e56dec89295ee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / mango_odm-0.4.1-py3-none-any.whl

Download URL mango_odm-0.4.1-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
762885a66992bd7c2109be845c1c161d2166dc85032d437545763f1233e0fa3a
BLAKE2b-256 checksum
How to use checksums
f6de6b075442099b44f4b801f4663607876afc69d4defd8a8ec8a003ffb56a18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page