
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
MongoDB-ODM, NOSQL databases in Python, designed for simplicity, compatibility, and robustness.
MongoDB-ODM, NOSQL databases in Python, designed for simplicity, compatibility, and robustness.
Documentation: https://mongodb-odm.readthedocs.io
PyPi: https://pypi.org/project/mongodb-odm
Repository: https://github.com/nayan32biswas/mongodb-odm
The purpose of this module is to provide easy access to the database with the python object feature with MongoDB and PyMongo. With PyMongo that was very easy to make spelling mistakes in a collection name when you are doing database operation. This module provides you with minimal ODM with a modeling feature so that you don’t have to look up the MongoDB dashboard(Mongo Compass) to know about field names or data types.
MongoDB-ODM is based on Python type annotations, and powered by PyMongo and Pydantic.
The key features are:
MongoDB-ODM will work on Python 3.8 and above
This MongoDB-ODM is built on top of PyMongo and Pydantic. Those packages are required and will auto-install while MongoDB-ODM was installed.
$ pip install mongodb-odm
import os
from typing import Optional
from mongodb_odm import ASCENDING, Document, IndexModel, connect
class Player(Document):
name: str
country_code: str
rating: Optional[int] = None
class ODMConfig(Document.ODMConfig):
indexes = [
IndexModel([("rating", ASCENDING)]),
]
connect(os.environ.get("MONGO_URL", "mongodb://localhost:27017/testdb"))
pele = Player(name="Pelé", country_code="BRA").create()
maradona = Player(name="Diego Maradona", country_code="ARG", rating=97).create()
zidane = Player(name="Zinedine Zidane", country_code="FRA", rating=96).create()
for player in Player.find():
print(player)
player = Player.find_one({"name": "Pelé"})
player = Player.find_one({"name": "Pelé"})
if player:
player.rating = 98 # potential
player.update()
player = Player.find_one({"name": "Pelé"})
if player:
player.delete()
import os
from typing import Optional
from mongodb_odm import ASCENDING, Document, IndexModel, connect
class Player(Document):
name: str
country_code: str
rating: Optional[int] = None
class ODMConfig(Document.ODMConfig):
indexes = [
IndexModel([("rating", ASCENDING)]),
]
apply_indexes
from mongodb_odm
. Call the apply_indexes
function from your CLI. You can use Typer to implement CLI.This is the example of full code of above.
import os
from typing import Optional
from mongodb_odm import ASCENDING, Document, IndexModel, connect
class Player(Document):
name: str
country_code: str
rating: Optional[int] = None
class ODMConfig(Document.ODMConfig):
indexes = [
IndexModel([("rating", ASCENDING)]),
]
connect(os.environ.get("MONGO_URL", "mongodb://localhost:27017/testdb"))
pele = Player(name="Pelé", country_code="BRA").create()
maradona = Player(name="Diego Maradona", country_code="ARG", rating=97).create()
zidane = Player(name="Zinedine Zidane", country_code="FRA", rating=96).create()
for player in Player.find():
print(player)
player = Player.find_one({"name": "Pelé"})
if player:
player.rating = 98 # potential
player.update()
player = Player.find_one({"name": "Pelé"})
if player:
player.delete() # RIP
MongoDB-ODM is not framework dependent. We can use this package in any system. But we take special consideration being compatible with FastAPI and Flask.
This package is built on top of PyMongo and Pydantic.
Documentation generated by MkDocs and Material for MkDocs.
Documentation inspired by SQLModel.
But we use other packages for development and other purposes. Check pyproject.toml to know about all packages we use to build this package.
This project is licensed under the terms of the MIT license.
FAQs
MongoDB-ODM, NOSQL databases in Python, designed for simplicity, compatibility, and robustness.
We found that mongodb-odm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.