A MongoDB ORM for Python
Project description
mongo-orm
A MongoDB ORM for Python
Usage
Defining an Entity
Use the @entity decorator to map a class to a MongoDB collection. Your class should inherit from BaseEntity.
from mongo_orm import BaseEntity, entity
@entity("users")
class User(BaseEntity):
name: str
email: str
# Define indexes
__indexes__ = [
{"keys": [("email", 1)], "unique": True},
{"keys": [("name", 1)]}
]
Index Management
The ORM can automatically manage your MongoDB indexes based on the __indexes__ attribute. This behavior is controlled by the MONGODB_INDEX_AUTOAPPLY environment variable.
Configuration (MONGODB_INDEX_AUTOAPPLY)
never(default): No automatic index management.always: Checks and applies indexes every time an entity class is initialized (on startup).auto-lock: Checks and applies indexes once. After a successful check, it writes a hash of the index tomongo-orm.lock. Subsequent startups will skip the check if the hash is present in the lock file.
Manual Index Application
You can also trigger index application manually for all registered entities:
from mongo_orm.utils import apply_all_indexes
# Apply indexes using the current environment configuration
apply_all_indexes()
# Or force a specific mode
apply_all_indexes(mode="always")
Development
# Install dependencies
poetry install
# Run tests
poetry run pytest
# Format code
poetry run black .
poetry run isort .
# Type checking
poetry run mypy src/
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongo_entity_orm-0.1.1.tar.gz.
File metadata
- Download URL: mongo_entity_orm-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.3 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d6c765ed18927c2693558205ece053cc4d61855df561a3aa754fbc240f86ca
|
|
| MD5 |
22df1b966dbba03939582e294eb24420
|
|
| BLAKE2b-256 |
d97be092f1b0fb52e11a95e37d803735c11962aa3e05c82f27b4a86e4900096f
|
File details
Details for the file mongo_entity_orm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mongo_entity_orm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.3 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52960707fb5c02601c52897c936468e84ea4b506f6baf8bd95e0c9a0743e5ff5
|
|
| MD5 |
3ef5ae9f8c4f4e20fe0773ac4455b497
|
|
| BLAKE2b-256 |
2b68f8d84e4277cefceca5a03e641cef94173a765eebb5548ddbbaf55b16239d
|