Mongoflex
Mongoflex is a ORM-like wrapper for mongodb to allow declarative creation and management of mongo collections.
Installation
pip install mongoflex
Usage
First you need to connect to a mongodb database:
from mongoflex import connect
connect("mongodb://localhost:27017/test")
And define a model for your collection using python dataclass syntax and extending mongoflex Model class.
from dataclasses import dataclass
from mongoflex import Model
@dataclass
class Person(Model):
age: int
name: str
You can create a record with:
>>> Person(age=10, name="John").save()
>>> list(Person.objects.find())
[{'_id': ObjectId('64d53e4e137297ea7f307086'), 'age': 10, 'name': 'John'}]
And you have full access to pymongo Collection using:
>>> Person.objects # Collection
Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'test'), 'people')
Important Points
- The name of the collection on mongo will be the combination of the words in the name of the
Modelclass, with the last pluralized. eg.:FeedConfigwill becomefeed_configson mongodb. - The
_idis a default field on every model, but you can define it on constructor.
Metadata
Release files for mongoflex 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongoflex-0.3.0.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongoflex-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / mongoflex-0.3.0.tar.gz
| Download URL | mongoflex-0.3.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92e8a68307e4feaf20f58edc60812536e97d67a46e823cb3fe240a33d4964a7d
|
|
BLAKE2b-256 checksum How to use checksums |
404e826594246597d5734cef2166ff7db367da3a0974295aac3f03b0a30c3894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.5 Linux/6.5.9-arch2-1
|
Release files / mongoflex-0.3.0-py3-none-any.whl
| Download URL | mongoflex-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a2e56dcbfed483fc4e30efa7ed110fc177872b3ea1486dc0d5f0ebae6203715
|
|
BLAKE2b-256 checksum How to use checksums |
84b422f6bae0cad678ed5dc072fa854dd54fc1caafa02f463ad715cb645da377
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.5 Linux/6.5.9-arch2-1
|