<p align="center">
<a name="readme-top"></a>
<a href="https://github.com/A-kirami/mango">
<img width="140px" src="https://raw.githubusercontent.com/A-kirami/mango/main/assets/mango-logo.svg" align="center" alt="Mango" />
</a>
<h1 align="center">Mango</h1>
<p align="center">🥭 带有类型提示的 Python 异步 MongoDB 对象文档映射器</p>
</p>
<p align="center">
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/A-kirami/mango.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/mango-odm">
<img src="https://img.shields.io/pypi/v/mango-odm.svg" alt="pypi">
</a>
<a href="https://www.python.org/">
<img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="python">
</a>
</p>
<p align="center">
<a href="#-示例">查看演示</a>
·
<a href="https://github.com/A-kirami/mango/issues/new?assignees=&labels=bug&template=bug_report.yml&title=%5BBUG%5D%3A+">错误报告</a>
·
<a href="https://github.com/A-kirami/mango/issues/new?assignees=&labels=enhancement&template=feature_request.yml&title=%5BFeature%5D%3A+">功能请求</a>
</p>
<p align="center">
<strong>简体中文</strong>
·
<a href="/docs/README_EN.md">English</a>
·
<a href="/docs/README_JA.md">日本語</a>
</p>
## 🔖 目录
<details open="open">
<summary>目录</summary>
<ul>
<li>
<a href="#-简介">简介</a>
<ul>
<li><a href="#-核心特性">核心特性</a></li>
</ul>
</li>
<li>
<a href="#-安装">安装</a>
<ul>
<li><a href="#PIP">PIP</a></li>
<li><a href="#Poetry">Poetry</a></li>
</ul>
</li>
<li>
<a href="#-示例">示例</a>
</li>
<li>
<a href="#-贡献">贡献</a>
<ul>
<li><a href="#-鸣谢">鸣谢</a></li>
</ul>
</li>
<li><a href="#-支持">支持</a></li>
<li><a href="#-许可证">许可证</a></li>
</ul>
</details>
## 📖 简介
Mango 是一个带有类型提示的 Python 异步 MongoDB 对象文档映射器(ODM),它构建在 [Motor](https://motor.readthedocs.io/en/stable/) 和 [Pydantic](https://pydantic-docs.helpmanual.io/) 之上。
Mango 使得数据建模和查询变得非常容易,帮助您关注应用程序中真正重要的部分。
### ✨ 核心特性:
- **完善的类型标注**:利用静态分析来减少运行时问题
- **简洁流畅的 API**:更易于学习和使用,提高开发效率
- **优雅的编辑器支持**:自动完成无处不在,从对象创建到查询结果
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
## 🚀 安装
### PIP
```shell
pip install mango-odm
```
### Poetry
```shell
poetry add mango-odm
```
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
## 🌟 示例
```python
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())
```
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
## 🤝 贡献
想为这个项目做出一份贡献吗?[点击这里]()阅读并了解如何贡献。
### 🎉 鸣谢
感谢以下开发者对该项目做出的贡献:
<a href="https://github.com/A-kirami/mango/graphs/contributors">
<img src="https://contrib.rocks/image?repo=A-kirami/mango" />
</a>
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
## 💖 支持
喜欢这个项目?请点亮 star 并分享它!
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
## 📝 许可证
在 `MIT` 许可证下分发。请参阅 [LICENSE](./LICENSE) 以获取更多信息。
<p align="right">[<a href="#readme-top">⬆回到顶部</a>]</p>
Raw data
{
"_id": null,
"home_page": null,
"name": "mango-odm",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "mongo mongodb async asyncio odm types pydantic motor",
"author": null,
"author_email": "Akirami <akiramiaya@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/cd/ad/c2d2594f6b0c8ef4f4eb529f2fc051517014ec4f8f8fd9f516015e401399/mango_odm-0.4.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a name=\"readme-top\"></a>\n <a href=\"https://github.com/A-kirami/mango\">\n <img width=\"140px\" src=\"https://raw.githubusercontent.com/A-kirami/mango/main/assets/mango-logo.svg\" align=\"center\" alt=\"Mango\" />\n </a>\n <h1 align=\"center\">Mango</h1>\n <p align=\"center\">\ud83e\udd6d \u5e26\u6709\u7c7b\u578b\u63d0\u793a\u7684 Python \u5f02\u6b65 MongoDB \u5bf9\u8c61\u6587\u6863\u6620\u5c04\u5668</p>\n</p>\n<p align=\"center\">\n <a href=\"./LICENSE\">\n <img src=\"https://img.shields.io/github/license/A-kirami/mango.svg\" alt=\"license\">\n </a>\n <a href=\"https://pypi.python.org/pypi/mango-odm\">\n <img src=\"https://img.shields.io/pypi/v/mango-odm.svg\" alt=\"pypi\">\n </a>\n <a href=\"https://www.python.org/\">\n <img src=\"https://img.shields.io/badge/python-3.10+-blue.svg\" alt=\"python\">\n </a>\n</p>\n<p align=\"center\">\n <a href=\"#-\u793a\u4f8b\">\u67e5\u770b\u6f14\u793a</a>\n \u00b7\n <a href=\"https://github.com/A-kirami/mango/issues/new?assignees=&labels=bug&template=bug_report.yml&title=%5BBUG%5D%3A+\">\u9519\u8bef\u62a5\u544a</a>\n \u00b7\n <a href=\"https://github.com/A-kirami/mango/issues/new?assignees=&labels=enhancement&template=feature_request.yml&title=%5BFeature%5D%3A+\">\u529f\u80fd\u8bf7\u6c42</a>\n</p>\n<p align=\"center\">\n <strong>\u7b80\u4f53\u4e2d\u6587</strong>\n \u00b7\n <a href=\"/docs/README_EN.md\">English</a>\n \u00b7\n <a href=\"/docs/README_JA.md\">\u65e5\u672c\u8a9e</a>\n</p>\n\n## \ud83d\udd16 \u76ee\u5f55\n\n<details open=\"open\">\n <summary>\u76ee\u5f55</summary>\n <ul>\n <li>\n <a href=\"#-\u7b80\u4ecb\">\u7b80\u4ecb</a>\n <ul>\n <li><a href=\"#-\u6838\u5fc3\u7279\u6027\">\u6838\u5fc3\u7279\u6027</a></li>\n </ul>\n </li>\n <li>\n <a href=\"#-\u5b89\u88c5\">\u5b89\u88c5</a>\n <ul>\n <li><a href=\"#PIP\">PIP</a></li>\n <li><a href=\"#Poetry\">Poetry</a></li>\n </ul>\n </li>\n <li>\n <a href=\"#-\u793a\u4f8b\">\u793a\u4f8b</a>\n </li>\n <li>\n <a href=\"#-\u8d21\u732e\">\u8d21\u732e</a>\n <ul>\n <li><a href=\"#-\u9e23\u8c22\">\u9e23\u8c22</a></li>\n </ul>\n </li>\n <li><a href=\"#-\u652f\u6301\">\u652f\u6301</a></li>\n <li><a href=\"#-\u8bb8\u53ef\u8bc1\">\u8bb8\u53ef\u8bc1</a></li>\n </ul>\n</details>\n\n## \ud83d\udcd6 \u7b80\u4ecb\n\nMango \u662f\u4e00\u4e2a\u5e26\u6709\u7c7b\u578b\u63d0\u793a\u7684 Python \u5f02\u6b65 MongoDB \u5bf9\u8c61\u6587\u6863\u6620\u5c04\u5668(ODM)\uff0c\u5b83\u6784\u5efa\u5728 [Motor](https://motor.readthedocs.io/en/stable/) \u548c [Pydantic](https://pydantic-docs.helpmanual.io/) \u4e4b\u4e0a\u3002\n\nMango \u4f7f\u5f97\u6570\u636e\u5efa\u6a21\u548c\u67e5\u8be2\u53d8\u5f97\u975e\u5e38\u5bb9\u6613\uff0c\u5e2e\u52a9\u60a8\u5173\u6ce8\u5e94\u7528\u7a0b\u5e8f\u4e2d\u771f\u6b63\u91cd\u8981\u7684\u90e8\u5206\u3002\n\n### \u2728 \u6838\u5fc3\u7279\u6027\uff1a\n\n- **\u5b8c\u5584\u7684\u7c7b\u578b\u6807\u6ce8**\uff1a\u5229\u7528\u9759\u6001\u5206\u6790\u6765\u51cf\u5c11\u8fd0\u884c\u65f6\u95ee\u9898\n- **\u7b80\u6d01\u6d41\u7545\u7684 API**\uff1a\u66f4\u6613\u4e8e\u5b66\u4e60\u548c\u4f7f\u7528\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\n- **\u4f18\u96c5\u7684\u7f16\u8f91\u5668\u652f\u6301**\uff1a\u81ea\u52a8\u5b8c\u6210\u65e0\u5904\u4e0d\u5728\uff0c\u4ece\u5bf9\u8c61\u521b\u5efa\u5230\u67e5\u8be2\u7ed3\u679c\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>\n\n## \ud83d\ude80 \u5b89\u88c5\n\n### PIP\n\n```shell\npip install mango-odm\n```\n### Poetry\n\n```shell\npoetry add mango-odm\n```\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>\n\n## \ud83c\udf1f \u793a\u4f8b\n\n```python\nimport asyncio\n\nfrom mango import Document, EmbeddedDocument, Field, Mango\n\n\n# \u5d4c\u5165\u5f0f\u6587\u6863\nclass Author(EmbeddedDocument):\n name: str\n profile: str | None = None\n\n\n# Mango \u6587\u6863\u6a21\u578b\nclass Book(Document):\n name: str = Field(primary_key=True) # \u5c06\u5b57\u6bb5\u8bbe\u7f6e\u4e3a\u4e3b\u952e\uff0c\u5982\u679c\u4e0d\u663e\u5f0f\u6307\u5b9a\u4e3b\u952e\uff0c\u5219\u4f1a\u81ea\u52a8\u521b\u5efa id \u5b57\u6bb5\u4f5c\u4e3a\u4e3b\u952e\n summary: str | None = None\n author: Author # \u5d4c\u5165\u6587\u6863\n price: int = Field(index=True) # \u4e3a\u5b57\u6bb5\u6dfb\u52a0\u7d22\u5f15\n\n\nasync def main():\n # \u521d\u59cb\u5316 Mango\uff0c\u5b83\u4f1a\u521b\u5efa\u8fde\u63a5\u5e76\u521d\u59cb\u5316\u6587\u6863\u6a21\u578b\uff0c\u4f60\u53ef\u4ee5\u4f20\u5165 db \u6216\u8005 uri \u53c2\u6570\u6765\u6307\u5b9a\u8fde\u63a5\n await Mango.init()\n\n # \u50cf pydantic \u7684\u6a21\u578b\u4e00\u6837\u4f7f\u7528\n book = Book(name=\"book\", author=Author(name=\"author\"), price=10)\n # \u5c06\u5b83\u63d2\u5165\u5230\u6570\u636e\u5e93\u4e2d\n await book.save()\n\n # Mango \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u67e5\u8be2\u8bed\u8a00\uff0c\u5141\u8bb8\u60a8\u4f7f\u7528 Python \u8868\u8fbe\u5f0f\u6765\u67e5\u8be2\n if book := await Book.find(Book.price <= 20, Book.author.name == \"author\").get():\n # \u66f4\u65b0\u6587\u6863\u7684 summary \u5b57\u6bb5\n book.summary = \"summary\"\n await book.update()\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n\n```\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>\n\n## \ud83e\udd1d \u8d21\u732e\n\n\u60f3\u4e3a\u8fd9\u4e2a\u9879\u76ee\u505a\u51fa\u4e00\u4efd\u8d21\u732e\u5417\uff1f[\u70b9\u51fb\u8fd9\u91cc]()\u9605\u8bfb\u5e76\u4e86\u89e3\u5982\u4f55\u8d21\u732e\u3002\n\n### \ud83c\udf89 \u9e23\u8c22\n\n\u611f\u8c22\u4ee5\u4e0b\u5f00\u53d1\u8005\u5bf9\u8be5\u9879\u76ee\u505a\u51fa\u7684\u8d21\u732e\uff1a\n\n<a href=\"https://github.com/A-kirami/mango/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=A-kirami/mango\" />\n</a>\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>\n\n## \ud83d\udc96 \u652f\u6301\n\n\u559c\u6b22\u8fd9\u4e2a\u9879\u76ee\uff1f\u8bf7\u70b9\u4eae star \u5e76\u5206\u4eab\u5b83\uff01\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>\n\n## \ud83d\udcdd \u8bb8\u53ef\u8bc1\n\n\u5728 `MIT` \u8bb8\u53ef\u8bc1\u4e0b\u5206\u53d1\u3002\u8bf7\u53c2\u9605 [LICENSE](./LICENSE) \u4ee5\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002\n\n<p align=\"right\">[<a href=\"#readme-top\">\u2b06\u56de\u5230\u9876\u90e8</a>]</p>",
"bugtrack_url": null,
"license": "MIT",
"summary": "\ud83e\udd6d Async MongoDB ODM with type hints in Python",
"version": "0.4.0",
"project_urls": {
"Repository": "https://github.com/A-kirami/mango"
},
"split_keywords": [
"mongo",
"mongodb",
"async",
"asyncio",
"odm",
"types",
"pydantic",
"motor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fdf70a83f0369f8309a000ebfd03fe4559be6d8fd4e30d7341713da26bcd21a7",
"md5": "d1085b14372bfaaaa87dffb18bc7cf21",
"sha256": "dbdfb2c8418a4ca4416e32470f7edb2d8d4cec121c8edbc10abd5281a8128681"
},
"downloads": -1,
"filename": "mango_odm-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d1085b14372bfaaaa87dffb18bc7cf21",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 24353,
"upload_time": "2024-04-11T16:30:11",
"upload_time_iso_8601": "2024-04-11T16:30:11.044368Z",
"url": "https://files.pythonhosted.org/packages/fd/f7/0a83f0369f8309a000ebfd03fe4559be6d8fd4e30d7341713da26bcd21a7/mango_odm-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cdadc2d2594f6b0c8ef4f4eb529f2fc051517014ec4f8f8fd9f516015e401399",
"md5": "8591f1935de2902e38bab75f34620660",
"sha256": "260e65747802a902afce5eb584731b2c3d1723266582dc89622612cd57b17517"
},
"downloads": -1,
"filename": "mango_odm-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "8591f1935de2902e38bab75f34620660",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 21822,
"upload_time": "2024-04-11T16:30:12",
"upload_time_iso_8601": "2024-04-11T16:30:12.758418Z",
"url": "https://files.pythonhosted.org/packages/cd/ad/c2d2594f6b0c8ef4f4eb529f2fc051517014ec4f8f8fd9f516015e401399/mango_odm-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-11 16:30:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "A-kirami",
"github_project": "mango",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mango-odm"
}