=========
pymongodm is a odm respecting pymongo functionality and adds
functionality such as model validation.
change your current orm by pymongodb.
Before:
.. figure:: http://i.imgur.com/8TTqJ9h.jpg
:alt: Imgur
Imgur
After:
.. figure:: http://i.imgur.com/NDna9Wp.jpg
:alt: Imgur
Imgur
https://pypi.python.org/pypi/pymongodm
install
-------
::
pip install pymongodm
connect db
----------
\`\`\`python import pymongodm
pymongodm.connect('name\_db') \`\`\`
or
\`\`\`python import pymongodm import pymongo
db = pymongo.MongoClient()['name\_db'] pymongodm.connect(db) \`\`\`
use db
------
\`\`\`python import pymongodm
pymongodm.connect('example\_db')
# Identical to pymongo pymongodm.db.nice\_collection.insert({'name':
'pepis'}) print(pymongodm.db.nice\_collection.find\_one()) \`\`\`
use models!
-----------
In version 2.0.0 change schema validator to cerberus (http://python-cerberus.org)
=================================================================================
\`\`\`python import pymongodm pymongodm.connect("gstudio")
from pymongodm.models import Base
class User(Base): schema = {"name": {'type': 'string'}, "other":
{'type': 'list', 'required': False}} # optional, default is class\_name
+ s collection\_name = "random\_name"
::
def cut_name(self):
return self.name[:3]
insert
======
result = User({'name': 'pepito'}) print("id in db", result.\_id)
convert dict to object Model
============================
a = User({'\_id': result.\_id, 'name': result.name}) b =
User(result.getattrs()) # get attrs return only db attrs c =
User(result.get\_clean()) # not return except arguments (exclude\_view )
d = User.find\_one({'\_id': result.\_id}) # normal query
convert result finds to model
=============================
results = pymongodm.db.users.find().model(User) # or results =
User.collect.find().model(User) # or result = User(id) # or result =
User.find()
for result in results: print(result.\_id) print(result.name)
print(result.cut\_name())
Modify values
=============
results = pymongodm.db.users.find().model(User) for result in results:
result.name = "Pymongodm\_%s" % result.name result.other = ["random",
"info"] result.update()
Remove
======
result.remove()
\`\`\`
Models options
~~~~~~~~~~~~~~
use other collection
^^^^^^^^^^^^^^^^^^^^
by default the name of the collection is the name of the class + s. It
can be changed with the following argument: collection =
"encoding\_profiles"
hidden arguments in returns
^^^^^^^^^^^^^^^^^^^^^^^^^^^
exclude\_view = ['name']
Rewrite basic methods
---------------------
Only need declare identic name in your class
.. code:: python
class User(Base):
schema = {"name": {'type': 'string'},
"other": {'type': 'list', 'required': False}}
# optional, default is class_name + s
collection_name = "random_name"
def remove(self):
print("uhm ...")
Plugins
=======
create new Plugins
------------------
.. code:: python
from pymongodm.models.plugins import Plugin
class new_schemaValidation(Plugin):
def __check(self, query):
print(query.fields) # all values
return {'success': False,
'errors': {'example': 'yep'}}
def pre_create(self, query):
return self.__check(query)
def pre_update(self, query):
return self.__check(query)
def post_create(self, query):
pass
def post_update(self, query):
pass
use new plugin
--------------
.. code:: python
class User(Base):
plugins = [new_schemaValidation]
schema = {"name": {'type': 'string'},
"other": {'type': 'list', 'required': False}}
- 2.0.3 (23-05-2017)
- add find() and find\_one()
- 2.0.2 (24-03-2017)
- support unset
- 2.0.1 (6-02-2017)
- Hack support ObjectId
- Fix minor bugs
- 2.0.0 (29-12-2016)
- (!!) Changed validation system to cerberus
(http://python-cerberus.org) check README.md
- 1.0.8 (12-12-2016)
- Support insert id by create method
- 1.0.7 (03-12-2016)
- Avoid recursive validation (inspect\_recursive=False)
- 1.0.6 (10-11-2016)
- Fix .model in find method
- 1.0.5 (05-10-2016)
- Fix remove item
- 1.0.4 (29-9-2016)
- support custom\_id
- 1.0.3 (28-9-2016)
- automatic creation
1.0.2 (18-7-2016)
=================
- add method insert()
1.0.1 (12-7-2016)
=================
- remove prints
1.0.0 (12-7-2016)
=================
- auto\_get = True
- disable automatic discover cache
- if you use auto\_get = False must make a .get() to get the data in
the class
- Add support Python 2
0.1.0 (11-7-2016)
=================
- Add collect property
0.0.5 (11-7-2016)
=================
- fix require=False and value None
0.0.4 (6-6-2016)
================
- Update readme
0.0.3 (6-6-2016)
================
- Update readme
- Fix minor bugs
0.0.2 (3-6-2016)
================
- Fix pip install
0.0.1 (3-6-2016)
================
- Initial version
Metadata
Release files for pymongodm 2.0.6
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 |
|---|---|---|---|---|
| pymongodm-2.0.6.tar.gz | 5.8 kB | Without provenance | Details for pymongodm-2.0.6.tar.gz |
Release files / pymongodm-2.0.6.tar.gz
| Download URL | pymongodm-2.0.6.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf273f056116f832183ba3d9b3bbd021f1f38459509460674bb0238895f8d92e
|
|
BLAKE2b-256 checksum How to use checksums |
e54ce46231ad2be194e360be8bd32c015483a8a4a2a97949e79ffd3c0ed5d84e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pymongodm 2.0.6
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.