modular-odm
A database-agnostic Document-Object Mapper for Python.
Install
$ pip install modular-odm
Example Usage with MongoDB
Defining Models
from modularodm import StoredObject, fields
from modularodm.validators import MinLengthValidator, MaxLengthValidator
class User(StoredObject):
_meta = {"optimistic": True}
_id = fields.StringField(primary=True, index=True)
username = fields.StringField(required=True)
password = fields.StringField(required=True, validate=[MinLengthValidator(8)])
def __repr__(self):
return "<User: {0}>".format(self.username)
class Comment(StoredObject):
_meta = {"optimistic": True}
_id = fields.StringField(primary=True, index=True)
text = fields.StringField(validate=MaxLengthValidator(500))
user = fields.ForeignField("User", backref="comments")
def __repr__(self):
return "<Comment: {0}>".format(self.text)
Setting the Storage Backend
from pymongo import MongoClient
from modularodm import storage
client = MongoClient()
db = client['testdb']
User.set_storage(storage.MongoStorage(db, collection="user"))
Comment.set_storage(storage.MongoStorage(db, collection="comment"))
Creating and Querying
>>> from modularodm.query.querydialect import DefaultQueryDialect as Q
>>> u = User(username="unladenswallow", password="h0lygrai1")
>>> u.save()
>>> comment = Comment(text="And now for something completely different.", user=u)
>>> comment2 = Comment(text="It's just a flesh wound.", user=u)
>>> comment.save()
True
>>> comment2.save()
True
>>> u = User.find_one(Q("username", "eq", "unladenswallow"))
>>> u.comment__comments
[<Comment: And now for something completely different.>, <Comment: It's just a flesh wound.>]
>>> c = Comment.find(Q("text", "startswith", "And now"))[0]
>>> c.text
'And now for something completely different.'
For more information regarding querying syntax, please visit the related readthedocs page at <http://modular-odm.readthedocs.org/en/latest/query_syntax.html>.
Migrations
TODO
Full documentation coming soon.
Development
Tests require nose, invoke, and MongoDB.
Installing MongoDB
If you are on MacOSX with homebrew, run
$ brew update
$ brew install mongodb
Running Tests
To start mongodb, run
$ invoke mongo
Run all tests with
$ invoke test
Metadata
Release files for modular-odm 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 | Provenance | Actions |
|---|---|---|---|---|
| modular-odm-0.3.0.tar.gz | 30.7 kB | Without provenance | Details for modular-odm-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modular_odm-0.3.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for modular_odm-0.3.0-py2.py3-none-any.whl |
Total release size: 72.6 kB
Release files / modular-odm-0.3.0.tar.gz
| Download URL | modular-odm-0.3.0.tar.gz |
|---|---|
| Size | 30.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c0dc303c638ea7bd78e6eaf329a727d0f9a53d4587d32b0930f32abce50fb7a
|
|
BLAKE2b-256 checksum How to use checksums |
194528fae0332525dccdca49edfc45bb6506020ee94a242cf34bcfa88d580943
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / modular_odm-0.3.0-py2.py3-none-any.whl
| Download URL | modular_odm-0.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 42.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
624db71ff7056934d7028239b62e858ff20f9b90d2ae08d6da363c86054dc80e
|
|
BLAKE2b-256 checksum How to use checksums |
73d3f7a5946600a0923fea6a0a8251ba77efb8dcca5a69fb46a757f937b121dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for modular-odm 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.