PyMODM是PyMongo之上的一个通用ODM。
项目描述
PyMODM是围绕MongoDB Python驱动程序PyMongo的一个通用ODM。PyMODM可以在Python 2.7以及Python 3.3及以上版本上运行。要了解更多信息,您可以浏览官方文档或查看一些示例。
为什么选择PyMODM?
PyMODM是一个“核心”ODM,这意味着它提供简单、可扩展的功能,可以被其他库利用以针对Django等平台。同时,PyMODM功能强大,足以独立用于开发应用程序。由于MongoDB工程师参与了项目的开发和维护,PyMODM也将迅速采用新的MongoDB功能。
支持/反馈
有关PyMODM的问题、疑问或反馈,请查阅我们的支持渠道。请不要直接通过电子邮件向任何PyMODM开发者发送有关问题或疑问 - 您更有可能在MongoDB社区论坛上获得答案。
错误/功能请求
发现了一个bug吗?想要看到PyMODM的新特性?请在我们的问题管理工具JIRA中创建一个案例。
JIRA中所有驱动项目(例如PYMODM、PYTHON、JAVA)和核心服务器(即SERVER)项目的问题报告是公开的。
如何寻求帮助
在打开问题时要包括以下所有信息
重现问题的详细步骤,包括完整的回溯,如果可能的话。
使用的Python版本,包括补丁级别
$ python -c "import sys; print(sys.version)"
使用的PyMODM版本,包括补丁级别
$ python -c "import pymodm; print(pymodm.version)"
使用的PyMongo版本,包括补丁级别
$ python -c "import pymongo; print(pymongo.version)"
操作系统和版本(例如Windows 7,OSX 10.8,……)
如果有的话,使用的Web框架或异步网络库,包括版本(例如Django 1.7,mod_wsgi 4.3.0,gevent 1.0.1,Tornado 4.0.2,……)
安全漏洞
如果你在驱动程序或其他MongoDB项目中发现了一个安全漏洞,请根据此处说明进行报告。
示例
以下是一个如何定义一些模型并将它们连接到MongoDB的基本示例。
from pymongo import TEXT
from pymongo.operations import IndexModel
from pymodm import connect, fields, MongoModel, EmbeddedMongoModel
# Connect to MongoDB first. PyMODM supports all URI options supported by
# PyMongo. Make sure also to specify a database in the connection string:
connect('mongodb://localhost:27017/myApp')
# Now let's define some Models.
class User(MongoModel):
# Use 'email' as the '_id' field in MongoDB.
email = fields.EmailField(primary_key=True)
fname = fields.CharField()
lname = fields.CharField()
class BlogPost(MongoModel):
# This field references the User model above.
# It's stored as a bson.objectid.ObjectId in MongoDB.
author = fields.ReferenceField(User)
title = fields.CharField(max_length=100)
content = fields.CharField()
tags = fields.ListField(fields.CharField(max_length=20))
# These Comment objects will be stored inside each Post document in the
# database.
comments = fields.EmbeddedDocumentListField('Comment')
class Meta:
# Text index on content can be used for text search.
indexes = [IndexModel([('content', TEXT)])]
# This is an "embedded" model and will be stored as a sub-document.
class Comment(EmbeddedMongoModel):
author = fields.ReferenceField(User)
body = fields.CharField()
vote_score = fields.IntegerField(min_value=0)
# Start the blog.
# We need to save these objects before referencing them later.
han_solo = User('mongoblogger@reallycoolmongostuff.com', 'Han', 'Solo').save()
chewbacca = User(
'someoneelse@reallycoolmongostuff.com', 'Chewbacca', 'Thomas').save()
post = BlogPost(
# Since this is a ReferenceField, we had to save han_solo first.
author=han_solo,
title="Five Crazy Health Foods Jabba Eats.",
content="...",
tags=['alien health', 'slideshow', 'jabba', 'huts'],
comments=[
Comment(author=chewbacca, body='Rrrrrrrrrrrrrrrr!', vote_score=42)
]
).save()
# Find objects using familiar MongoDB-style syntax.
slideshows = BlogPost.objects.raw({'tags': 'slideshow'})
# Only retrieve the 'title' field.
slideshow_titles = slideshows.only('title')
# u'Five Crazy Health Foods Jabba Eats.'
print(slideshow_titles.first().title)
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
构建分布
pymodm-0.4.3.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b9fc352dabca1c10bc9342167ab322ce2898b68a79c42e19f0baa7d5b7578ea1 |
|
MD5 | e30cd1871de72e00fade686cb1dcf880 |
|
BLAKE2b-256 | d068d2001233b684b8d32e988188c85def43a2ef6a4b1e8b074942c0c0120aff |
pymodm-0.4.3-py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 697b23d93695fdbaccc995912aecb203d1f1d8f8bff7ad90a9180f6a2986d084 |
|
MD5 | afe2f4ed48a451b66a259dd5959dcc18 |
|
BLAKE2b-256 | 1550d250e457eeb4bd49a9a0d26bbb5918a15689dac3b5b0d594beec11e30090 |
pymodm-0.4.3-py2-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 98e790bb457a7faf4e0aca71ff8a13d584eb6d9075db98202c8f1ce334675e55 |
|
MD5 | cdf1a4f6214865f8aaf6012eb0b4d50f |
|
BLAKE2b-256 | 30d226765629b9d984fc10a0f5abf2b3551c847c691d4f57b375205c06996dc4 |