Skip to main content

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

  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.

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.3.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongoflex-0.3.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file mongoflex-0.3.0.tar.gz.

File metadata

  • Download URL: mongoflex-0.3.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.5 Linux/6.5.9-arch2-1

File hashes

Hashes for mongoflex-0.3.0.tar.gz
Algorithm Hash digest
SHA256 92e8a68307e4feaf20f58edc60812536e97d67a46e823cb3fe240a33d4964a7d
MD5 0a3d3936a44d6b4132da302c6ef586af
BLAKE2b-256 404e826594246597d5734cef2166ff7db367da3a0974295aac3f03b0a30c3894

See more details on using hashes here.

File details

Details for the file mongoflex-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mongoflex-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.11.5 Linux/6.5.9-arch2-1

File hashes

Hashes for mongoflex-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2e56dcbfed483fc4e30efa7ed110fc177872b3ea1486dc0d5f0ebae6203715
MD5 ee2b12326952b6ce457d137171449ee9
BLAKE2b-256 84b422f6bae0cad678ed5dc072fa854dd54fc1caafa02f463ad715cb645da377

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page