Mongoflex is a ORM-like wrapper for mongodb to allow declarative creation and management of mongo collections.
Project description
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
Model
class, with the last pluralized. eg.:FeedConfig
will becomefeed_configs
on mongodb. - The
_id
is a default field on every model, but you can define it on constructor.
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
mongoflex-0.1.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for mongoflex-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 734af9e1a385c792af2d47054ce34e6b17580e1d4cab97085adb779fbd30148e |
|
MD5 | 599bf12734e63a94e52b3fa8e9be525c |
|
BLAKE2b-256 | 4abf3068d73f0128d52fc5e69542722fead1e96eb0bccbf6fd1c74cc29d944b4 |