Skip to main content

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

  1. 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 become feed_configs on mongodb.
  2. The _id is 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)

Source distribution for mongoflex 0.3.0
File Size Uploaded
mongoflex-0.3.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongoflex 0.3.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page