MongoX
MongoX is an async python ODM (Object Document Mapper) for MongoDB which is built on top of Motor and Pydantic.
The main features include:
- Fully type annotated
- Async support Python 3.7+ (since it's built on top of Motor)
- Elegant editor support (since it's built on top of Pydantic)
- Autocompletion everywhere, from object creation to query results
- Custom query builder which is more intuitive and pythonic
- 100% test coverage
MongoX models are at the same time Pydantic models and have the same functionalitties, so you can use them with your existing Pydantic models.
Documentation: https://aminalaee.github.io/mongox
Installation
$ pip install mongox
Quickstart
You can define mongox models the same way you define Pydantic models.
The difference is they should inherit from mongox.Model now:
import asyncio
import mongox
client = mongox.Client("mongodb://localhost:27017")
db = client.get_database("test_db")
class Movie(mongox.Model, db=db, collection="movies"):
name: str
year: int
Now you can create some instances and insert them into the database:
movie = await Movie(name="Forrest Gump", year=1994).insert()
The returned result will be a Movie instance, and mypy
will understand that this is a Movie instance.
So you will have type hints and validations everywhere.
Now you can fetch some data from the database.
You can use the same pattern as PyMongo/Motor:
movie = await Movie.query({"name": "Forrest Gump"}).get()
Or you can use Movie fields instead of dictionaries in the query (less room for bugs):
movie = await Movie.query({Movie.name: "Forrest Gump"}).get()
And finally you can use a more intuitive query (limited yet):
movie = await Movie.query(Movie.name == "Forrest Gump").get()
Notice how we omitted the dictionary and passed the Movie fields in comparison.
Please refer to the documentation here or the full examples here.
Metadata
Release files for mongox 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mongox-0.1.2.tar.gz | 11.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongox-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / mongox-0.1.2.tar.gz
| Download URL | mongox-0.1.2.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcb0d43fb2bfcdffbf9eeb02f57d0e7fdf6769622f9aa0fdaa0d540cacac4114
|
|
BLAKE2b-256 checksum How to use checksums |
993f770b7de49e7b733067d392d29f773e381e454622c761a0f96bb6917c6634
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure
|
Release files / mongox-0.1.2-py3-none-any.whl
| Download URL | mongox-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
89043e1c7c4aefa859d325ec4edb8917fc866e0f382ce1ee8770414adb3fe0ec
|
|
BLAKE2b-256 checksum How to use checksums |
0572717d652f52d37aab47540facc02ac8093fe670b7f2ac4c7ff868a135e4d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.9.15 Linux/5.15.0-1022-azure
|
Security for mongox 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.