pax_global_header 0000666 0000000 0000000 00000000064 14737013765 0014527 g ustar 00root root 0000000 0000000 52 comment=2190cd9d1fc047af477d5e6897cc283799f54064
python-beanie-1.29.0/ 0000775 0000000 0000000 00000000000 14737013765 0014362 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/ 0000775 0000000 0000000 00000000000 14737013765 0015722 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 14737013765 0020105 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/ISSUE_TEMPLATE/bug_report.md 0000664 0000000 0000000 00000000672 14737013765 0022604 0 ustar 00root root 0000000 0000000 ---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
```python
Please add a code snippet here, that reproduces the problem completely
```
**Expected behavior**
A clear and concise description of what you expected to happen.
**Additional context**
Add any other context about the problem here.
python-beanie-1.29.0/.github/ISSUE_TEMPLATE/config.yml 0000664 0000000 0000000 00000000746 14737013765 0022104 0 ustar 00root root 0000000 0000000 blank_issues_enabled: true
contact_links:
- name: Question
url: 'https://github.com/roman-right/beanie/discussions/new?category=question'
about: Ask a question about how to use Beanie using github discussions
- name: Feature Request
url: 'https://github.com/roman-right/beanie/discussions/new?category=feature-request'
about: >
If you think we should add a new feature to Beanie, please start a discussion, once it attracts
wider support, it can be migrated to an issue python-beanie-1.29.0/.github/scripts/ 0000775 0000000 0000000 00000000000 14737013765 0017411 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/scripts/handlers/ 0000775 0000000 0000000 00000000000 14737013765 0021211 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/scripts/handlers/__init__.py 0000664 0000000 0000000 00000000000 14737013765 0023310 0 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/scripts/handlers/gh.py 0000664 0000000 0000000 00000005473 14737013765 0022172 0 ustar 00root root 0000000 0000000 import subprocess
from dataclasses import dataclass
from datetime import datetime
from typing import List
import requests # type: ignore
@dataclass
class PullRequest:
number: int
title: str
user: str
user_url: str
url: str
class GitHubHandler:
def __init__(
self,
username: str,
repository: str,
current_version: str,
new_version: str,
):
self.username = username
self.repository = repository
self.base_url = f"https://api.github.com/repos/{username}/{repository}"
self.current_version = current_version
self.new_version = new_version
self.commits = self.get_commits_after_tag(current_version)
self.prs = [self.get_pr_for_commit(commit) for commit in self.commits]
def get_commits_after_tag(self, tag: str) -> List[str]:
result = subprocess.run(
["git", "log", f"{tag}..HEAD", "--pretty=format:%H"],
stdout=subprocess.PIPE,
text=True,
)
return result.stdout.split()
def get_pr_for_commit(self, commit_sha: str) -> PullRequest:
url = f"{self.base_url}/commits/{commit_sha}/pulls"
response = requests.get(url)
response.raise_for_status()
pr_data = response.json()[0]
return PullRequest(
number=pr_data["number"],
title=pr_data["title"],
user=pr_data["user"]["login"],
user_url=pr_data["user"]["html_url"],
url=pr_data["html_url"],
)
def build_markdown_for_many_prs(self) -> str:
markdown = f"\n## [{self.new_version}] - {datetime.now().strftime('%Y-%m-%d')}\n"
for pr in self.prs:
markdown += (
f"### {pr.title.capitalize()}\n"
f"- Author - [{pr.user}]({pr.user_url})\n"
f"- PR <{pr.url}>\n"
)
markdown += f"\n[{self.new_version}]: https://pypi.org/project/{self.repository}/{self.new_version}\n"
return markdown
def commit_changes(self):
self.run_git_command(
["git", "config", "--global", "user.name", "github-actions[bot]"]
)
self.run_git_command(
[
"git",
"config",
"--global",
"user.email",
"github-actions[bot]@users.noreply.github.com",
]
)
self.run_git_command(["git", "add", "."])
self.run_git_command(
["git", "commit", "-m", f"Bump version to {self.new_version}"]
)
self.run_git_command(["git", "tag", self.new_version])
self.git_push()
def git_push(self):
self.run_git_command(["git", "push", "origin", "main", "--tags"])
@staticmethod
def run_git_command(command: List[str]):
subprocess.run(command, check=True)
python-beanie-1.29.0/.github/scripts/handlers/version.py 0000664 0000000 0000000 00000007161 14737013765 0023255 0 ustar 00root root 0000000 0000000 import subprocess
from pathlib import Path
import requests # type: ignore
import toml
from gh import GitHubHandler
class SemVer:
def __init__(self, version: str):
self.version = version
self.major, self.minor, self.patch = map(int, self.version.split("."))
def increment_minor(self):
return SemVer(f"{self.major}.{self.minor + 1}.0")
def __str__(self):
return self.version
def __eq__(self, other):
return self.version == other.version
def __gt__(self, other):
return (
(self.major > other.major)
or (self.major == other.major and self.minor > other.minor)
or (
self.major == other.major
and self.minor == other.minor
and self.patch > other.patch
)
)
class VersionHandler:
PACKAGE_NAME = "beanie"
ROOT_PATH = Path(__file__).parent.parent.parent.parent
def __init__(self):
self.pyproject = self.ROOT_PATH / "pyproject.toml"
self.init_py = self.ROOT_PATH / "beanie" / "__init__.py"
self.changelog = self.ROOT_PATH / "docs" / "changelog.md"
self.current_version = self.parse_version_from_pyproject(
self.pyproject
)
self.pypi_version = self.get_version_from_pypi()
if self.current_version < self.pypi_version:
raise ValueError("Current version is less than pypi version")
if self.current_version == self.pypi_version:
self.current_version = self.current_version.increment_minor()
self.update_files()
else:
self.flit_publish()
@staticmethod
def parse_version_from_pyproject(pyproject: Path) -> SemVer:
toml_data = toml.loads(pyproject.read_text())
return SemVer(toml_data["project"]["version"])
def get_version_from_pypi(self) -> SemVer:
response = requests.get(
f"https://pypi.org/pypi/{self.PACKAGE_NAME}/json"
)
if response.status_code == 200:
return SemVer(response.json()["info"]["version"])
raise ValueError("Can't get version from pypi")
def update_files(self):
self.update_pyproject_version()
self.update_file_versions([self.init_py])
self.update_changelog()
def update_pyproject_version(self):
pyproject = toml.loads(self.pyproject.read_text())
pyproject["project"]["version"] = str(self.current_version)
self.pyproject.write_text(toml.dumps(pyproject))
def update_file_versions(self, files_to_update):
for file_path in files_to_update:
content = file_path.read_text()
content = content.replace(
str(self.pypi_version), str(self.current_version)
)
file_path.write_text(content)
def update_changelog(self):
handler = GitHubHandler(
"BeanieODM",
"beanie",
str(self.pypi_version),
str(self.current_version),
)
changelog_content = handler.build_markdown_for_many_prs()
changelog_lines = self.changelog.read_text().splitlines()
new_changelog_lines = []
inserted = False
for line in changelog_lines:
new_changelog_lines.append(line)
if line.strip() == "# Changelog" and not inserted:
new_changelog_lines.append(changelog_content)
inserted = True
self.changelog.write_text("\n".join(new_changelog_lines))
handler.commit_changes()
def flit_publish(self):
subprocess.run(["flit", "publish"], check=True)
if __name__ == "__main__":
VersionHandler()
python-beanie-1.29.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14737013765 0017757 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/.github/workflows/close_inactive_issues.yml 0000664 0000000 0000000 00000001610 14737013765 0025062 0 ustar 00root root 0000000 0000000 name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"
jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity.'
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity.'
close-issue-message: 'This issue was closed because it has been stalled for 14 days with no activity.'
close-pr-message: 'This PR was closed because it has been stalled for 14 days with no activity.'
exempt-issue-labels: 'bug,feature-request,typing bug,feature request,doc,documentation'
days-before-issue-stale: 30
days-before-pr-stale: 45
days-before-issue-close: 14
days-before-pr-close: 14 python-beanie-1.29.0/.github/workflows/github-actions-publish-docs.yml 0000664 0000000 0000000 00000000565 14737013765 0026022 0 ustar 00root root 0000000 0000000 name: Publish docs
on:
push:
branches:
- main
jobs:
publish_docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: 3.10.9
- name: install dependencies
run: pip3 install .[doc]
- name: publish docs
run: bash scripts/publish_docs.sh python-beanie-1.29.0/.github/workflows/github-actions-publish-project.yml 0000664 0000000 0000000 00000000565 14737013765 0026540 0 ustar 00root root 0000000 0000000 name: Publish project
on:
push:
branches:
- main
jobs:
publish_project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install flit
run: pip3 install flit
- name: publish project
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
run: flit publish python-beanie-1.29.0/.github/workflows/github-actions-tests.yml 0000664 0000000 0000000 00000002257 14737013765 0024570 0 ustar 00root root 0000000 0000000 name: Tests
on:
pull_request:
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: pre-commit/action@v3.0.1
run-tests:
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
mongodb-version: [ "4.4", "5.0", "6.0", "7.0", "8.0" ]
pydantic-version: [ "1.10.18", "2.9.2" , "2.10.4"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-replica-set: test-rs
- name: install dependencies
run: pip install .[test,ci]
- name: install pydantic
run: pip install pydantic==${{ matrix.pydantic-version }}
- name: run tests
env:
PYTHON_JIT: 1
run: pytest -v
python-beanie-1.29.0/.gitignore 0000664 0000000 0000000 00000005114 14737013765 0016353 0 ustar 00root root 0000000 0000000 config.cnf
*.pyc
*.iml
*/*.pytest*
.rnd
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
.static_storage/
.media/
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
pyvenv.cfg
.venv
pip-selfcheck.json
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.idea
.pytest_cache
docs/api
docs/_rst
tags
tests/assets/tmp
src/api_files/storage_dir
docker-compose-aws.yml
tilt_modules
# Poetry stuff
poetry.lock
.pdm-python
python-beanie-1.29.0/.pre-commit-config.yaml 0000664 0000000 0000000 00000000551 14737013765 0020644 0 ustar 00root root 0000000 0000000 repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- types-click
- types-toml
exclude: ^tests/
python-beanie-1.29.0/.pypirc 0000664 0000000 0000000 00000000402 14737013765 0015665 0 ustar 00root root 0000000 0000000 [distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = ${PYPI_TOKEN}
[testpypi]
repository = https://test.pypi.org/legacy/
username = roman-right
password = =$C[wT}^]5EWvX(p#9Po python-beanie-1.29.0/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000000207 14737013765 0017160 0 ustar 00root root 0000000 0000000 Code of Conduct
---------------
Please check [this page in the documentation](https://roman-right.github.io/beanie/code-of-conduct/).
python-beanie-1.29.0/CONTRIBUTING.md 0000664 0000000 0000000 00000000157 14737013765 0016616 0 ustar 00root root 0000000 0000000 Contributing
------------
Please check [this page in the documentation](https://beanie-odm.dev/development/).
python-beanie-1.29.0/LICENSE 0000664 0000000 0000000 00000026117 14737013765 0015376 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2021 Roman Korolev
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
python-beanie-1.29.0/README.md 0000664 0000000 0000000 00000012741 14737013765 0015646 0 ustar 00root root 0000000 0000000 [](https://github.com/roman-right/beanie)
[](https://beanie-odm.dev)
[](https://pypi.python.org/pypi/beanie)
## 📢 Important Update 📢
We are excited to announce that Beanie is transitioning from solo development to a team-based approach! This move will help us enhance the project with new features and more collaborative development.
At this moment we are establishing a board of members that will decide all the future steps of the project. We are looking for contributors and maintainers to join the board.
### Join Us
If you are interested in contributing or want to stay updated, please join our Discord channel. We're looking forward to your ideas and contributions!
[Join our Discord](https://discord.gg/AwwTrbCASP)
Let’s make Beanie better, together!
## Overview
[Beanie](https://github.com/roman-right/beanie) - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on [Pydantic](https://pydantic-docs.helpmanual.io/).
When using Beanie each database collection has a corresponding `Document` that
is used to interact with that collection. In addition to retrieving data,
Beanie allows you to add, update, or delete documents from the collection as
well.
Beanie saves you time by removing boilerplate code, and it helps you focus on
the parts of your app that actually matter.
Data and schema migrations are supported by Beanie out of the box.
There is a synchronous version of Beanie ODM - [Bunnet](https://github.com/roman-right/bunnet)
## Installation
### PIP
```shell
pip install beanie
```
### Poetry
```shell
poetry add beanie
```
For more installation options (eg: `aws`, `gcp`, `srv` ...) you can look in the [getting started](./docs/getting-started.md#optional-dependencies)
## Example
```python
import asyncio
from typing import Optional
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseModel
from beanie import Document, Indexed, init_beanie
class Category(BaseModel):
name: str
description: str
class Product(Document):
name: str # You can use normal types just like in pydantic
description: Optional[str] = None
price: Indexed(float) # You can also specify that a field should correspond to an index
category: Category # You can include pydantic models as well
# This is an asynchronous example, so we will access it from an async function
async def example():
# Beanie uses Motor async client under the hood
client = AsyncIOMotorClient("mongodb://user:pass@host:27017")
# Initialize beanie with the Product document class
await init_beanie(database=client.db_name, document_models=[Product])
chocolate = Category(name="Chocolate", description="A preparation of roasted and ground cacao seeds.")
# Beanie documents work just like pydantic models
tonybar = Product(name="Tony's", price=5.95, category=chocolate)
# And can be inserted into the database
await tonybar.insert()
# You can find documents with pythonic syntax
product = await Product.find_one(Product.price < 10)
# And update them
await product.set({Product.name:"Gold bar"})
if __name__ == "__main__":
asyncio.run(example())
```
## Links
### Documentation
- **[Doc](https://beanie-odm.dev/)** - Tutorial, API documentation, and development guidelines.
### Example Projects
- **[fastapi-cosmos-beanie](https://github.com/tonybaloney/ants-azure-demos/tree/master/fastapi-cosmos-beanie)** - FastAPI + Beanie ODM + Azure Cosmos Demo Application by [Anthony Shaw](https://github.com/tonybaloney)
- **[fastapi-beanie-jwt](https://github.com/flyinactor91/fastapi-beanie-jwt)** -
Sample FastAPI server with JWT auth and Beanie ODM by [Michael duPont](https://github.com/flyinactor91)
- **[Shortify](https://github.com/IHosseini083/Shortify)** - URL shortener RESTful API (FastAPI + Beanie ODM + JWT & OAuth2) by [
Iliya Hosseini](https://github.com/IHosseini083)
- **[LCCN Predictor](https://github.com/baoliay2008/lccn_predictor)** - Leetcode contest rating predictor (FastAPI + Beanie ODM + React) by [L. Bao](https://github.com/baoliay2008)
### Articles
- **[Announcing Beanie - MongoDB ODM](https://dev.to/romanright/announcing-beanie-mongodb-odm-56e)**
- **[Build a Cocktail API with Beanie and MongoDB](https://developer.mongodb.com/article/beanie-odm-fastapi-cocktails/)**
- **[MongoDB indexes with Beanie](https://dev.to/romanright/mongodb-indexes-with-beanie-43e8)**
- **[Beanie Projections. Reducing network and database load.](https://dev.to/romanright/beanie-projections-reducing-network-and-database-load-3bih)**
- **[Beanie 1.0 - Query Builder](https://dev.to/romanright/announcing-beanie-1-0-mongodb-odm-with-query-builder-4mbl)**
- **[Beanie 1.8 - Relations, Cache, Actions and more!](https://dev.to/romanright/announcing-beanie-odm-18-relations-cache-actions-and-more-24ef)**
### Resources
- **[GitHub](https://github.com/roman-right/beanie)** - GitHub page of the
project
- **[Changelog](https://beanie-odm.dev/changelog)** - list of all
the valuable changes
- **[Discord](https://discord.gg/AwwTrbCASP)** - ask your questions, share
ideas or just say `Hello!!`
----
Supported by [JetBrains](https://jb.gg/OpenSource)
[](https://jb.gg/OpenSource)
python-beanie-1.29.0/assets/ 0000775 0000000 0000000 00000000000 14737013765 0015664 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/assets/logo/ 0000775 0000000 0000000 00000000000 14737013765 0016624 5 ustar 00root root 0000000 0000000 python-beanie-1.29.0/assets/logo/jetbrains.svg 0000664 0000000 0000000 00000011416 14737013765 0021331 0 ustar 00root root 0000000 0000000
python-beanie-1.29.0/assets/logo/logo.svg 0000664 0000000 0000000 00000005643 14737013765 0020315 0 ustar 00root root 0000000 0000000