{ "info": { "author": "Jason Moiron", "author_email": "jmoiron@jmoiron.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Database :: Front-Ends" ], "description": "micromongo\n==========\n\nmicromongo is a tiny layer around pymongo that allows you to create simple\nORM-style classes that can perform validation, allow dot access to documents,\nauto-wrap queryset results, and give you pre/post save hooks.\n\nIt's designed with microframeworks in mind, but is application and framework\nagnostic. It is meant to simplify usage of pymongo and provide tools for\ncommon idioms, not to obscure pymongo or mongodb from your data structures.\n\nYou are welcome to open issues or send pull requests on `micromongo's github`_\n\n.. _`micromongo's github`: https://github.com/jmoiron/micromongo\n\n``micromongo`` makes a few design decisions in the name of simplification that\nmight not work for you:\n\n* micromongo maintains a single global connection, so you cannot have models \n that connect to multiple mongodb servers\n* there are a handfull of model names and document attribute names that will\n not work with micromongo models; these will be covered in the `full docs`_\n* you can only have one model per collection\n\n.. _`full docs`: http://packages.python.org/micromongo/\n\ngetting started\n---------------\n\nTo start off with micromongo, just import it::\n\n >>> from micromongo import connect, Model\n >>> c = connect()\n\n``connect`` takes the same arguments as `pymongo's Connection`_ object, and\nbehaves almost identically, except that it attempts to automatically return\nquery results wrapped in the appropriate Model classes. The connection object\nthat you create via this call will be cached and used by the various ORM-style\nfacilities, like ``Model.save()``, ``Model.proxy``, etc. If you want a clean,\nstandard ``Connection`` object, you can get one easily::\n\n >>> from micromongo import clean_connection\n >>> clean = clean_connection()\n\nNote that clean_connection does not take arguments and will always return a\nclean ``Connection`` class with the same settings as the current micromongo \nconnection.\n\nWith these connection objects, you can create databases or do whatever you\nwould with normal ``pymongo`` objects::\n\n >>> db = c.test_db\n >>> collection = db.test_collection\n >>> collection.save({\"docid\": 1, \"fail\": False})\n >>> collection.find_one()\n {u'_id': ObjectId('...'), u'fail': False, u'docid': 1}\n\nYou can also declare your own Model for a particular collection in\ndeclarative style::\n\n >>> class TestModel(Model):\n collection = 'test_db.test_collection'\n\n >>> collection.find_one()\n \n\nThese classes have a number of additional features over a dictionary that can\nmake them much more convenient to use. The document keys are all accessible\nas attributes::\n\n >>> t = collection.find_one()\n >>> t.fail\n False\n >>> t.docid\n 1\n\nThe documents are also easily persisted to the database::\n\n >>> t.docid = 17\n >>> t.save()\n >>> clean.test_db.test_collection.find_one()\n {u'_id': ObjectId('...'), u'fail': False, u'docid': 17}\n\ndefining models\n---------------\n\nAbove, the ``collection`` attribute was assigned to our ``Foo`` model. This\nwas a shortcut, though; if ``database`` and ``collection`` are assigned\nseparately, the Model can figure out the full collection name. If the\ncollection and database are not present, micromongo attempts to figure it out\nbased on the class and module name of your Model. For instance, ``blog.Post``\nwill become ``blog.post``, or ``stream.StreamEntry`` will become\n``stream.stream_entry``. Explicit is better than implicit, and it's encouraged\nthat you set the collection manually.\n\nBesides packing and unpacking results from the database, models can also define\na ``spec`` document which can define defaults and perform validation before\nsaving the model. Take a trivial blog post model::\n\n >>> from micromongo.spec import *\n >>> class Post(Model):\n collection = 'test_db.blog_posts'\n spec = dict(\n author=Field(required=True, default='jmoiron', type=basestring),\n title=Field(required=False, default='', type=basestring),\n published=Field(required=True, default=False, type=[True, False]),\n body=Field(type=unicode),\n timestamp=Field(),\n )\n\n >>> p = Post.new()\n >>> p\n \n\nA few things are going on here. Fields that have a default are initialized to\nthat default whether they are required or not. If a required field does not\nhave a default, it's initialized to ``None``.\n\nFields can take a ``type`` argument, which can either be a callable that takes\na value and returns True or False, one or more base types, or one or more\nvalues. If one or more types are provided, ``isinstance`` is used to test that\nvalues are the right type. If one or more values are provided, the Field acts\nas an enum type, checking that values are in its set of values. If no type is\ngiven, validation always passes on a field *unless* it is required and absent.\n\nIf a field in p is given an invalid type, then a ``ValueError`` is raised::\n\n >>> p.title = 10\n >>> p.save()\n Traceback (most recent call last):\n ...\n ValueError: Keys did not match spec: ['title']\n >>> del p.author\n >>> p.save()\n Traceback (most recent call last):\n ...\n ValueError: Missing fields: ['author'], Invalid fields: ['title']\n >>> p.title = 'My first blogpost'\n >>> p.author = 'jmoiron'\n >>> p.published = True\n >>> p.body = u\"This is my first blog post.. I'm so excited!\"\n >>> p.save()\n\nModel.find\n~~~~~~~~~~\n\nFor convenience and DRY, ``Model.find`` is a classmethod that will use\nmicromongo's cursor to issue a find against the right collection. This method\nbehaves exactly the same as `pymongo's Collection.find`_.\n\nmicromongo's slightly modified ``Cursor`` class also makes a django-inspired\n``order_by`` method available to all cursors (``find`` and anything you chain\noff if it returns a cursor). You can pass one or more field names, with an\noptional leading '-', to sort things by ascending or descending order.\n\nThese changes allow you to use most of the power of pymongo without having to\nimport it, and lets you avoid needless repetition of the location of your data.\n\nfield subclassing\n~~~~~~~~~~~~~~~~~\n\nYou are encouraged to create your own Fields that do what you want. Field \nsubclasses have a hook function ``pre_validate`` which take an incoming value\nand can transform it however they want. Note that this will only work if the\nfields are actually present; so to get something like an ``auto_now_add`` on a\n``DateTimeField``, you will want to make it required and have its\n``pre_validate`` turn ``None`` into ``datetime.datetime.now()``.\n\n\n.. _`pymongo's Connection`: http://api.mongodb.org/python/current/api/pymongo/connection.html\n.. _`pymongo's Collection.find`: http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find", "description_content_type": null, "docs_url": "https://pythonhosted.org/micromongo/", "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/jmoiron/micromongo", "keywords": "mongodb orm", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "micromongo", "package_url": "https://pypi.org/project/micromongo/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/micromongo/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/jmoiron/micromongo" }, "release_url": "https://pypi.org/project/micromongo/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "small natural object/mongodb driver", "version": "0.1.4" }, "last_serial": 794773, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "10c0714de869e9cc227347fe3e839610", "sha256": "09ab66dbc8a41ef1cbb9aff29060bfb262465db03a03d43b9b4e1be49416d6ee" }, "downloads": -1, "filename": "micromongo-0.1.tar.gz", "has_sig": false, "md5_digest": "10c0714de869e9cc227347fe3e839610", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9450, "upload_time": "2011-04-26T06:03:42", "url": "https://files.pythonhosted.org/packages/6c/68/362e5e470a18b8b7fd6c4663281b119df2724796059f26b98accf90b92f9/micromongo-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "84b7e2841794f6ba2e033906fd8b9ba6", "sha256": "f297fbf7549fd1e4e365da5fb7af758188bd051c8aa6562cf425cb20b0c774ec" }, "downloads": -1, "filename": "micromongo-0.1.1.tar.gz", "has_sig": false, "md5_digest": "84b7e2841794f6ba2e033906fd8b9ba6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11808, "upload_time": "2011-06-14T06:54:18", "url": "https://files.pythonhosted.org/packages/5f/80/9658f8775903412dc1e6ba4399de3fd89dc7f74a0fe0883a7e028e42c475/micromongo-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "03acaa1efc0d1df4ade17108b4a26c81", "sha256": "efa42de1c66ea01facefb4a2b182ba790624210ba0a7d36e6853915d23251692" }, "downloads": -1, "filename": "micromongo-0.1.2.tar.gz", "has_sig": false, "md5_digest": "03acaa1efc0d1df4ade17108b4a26c81", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11968, "upload_time": "2011-06-18T07:24:39", "url": "https://files.pythonhosted.org/packages/9a/6f/15485dbf871e957dbede7a791be7975f952a0e14825fd296d8ba522e5397/micromongo-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "472e50222294759445aca09e604cdf59", "sha256": "9b65d4c0c906828e05d3e0da3cc1ce76e865f17c0ff68988a3f344a6c3fd599e" }, "downloads": -1, "filename": "micromongo-0.1.3.tar.gz", "has_sig": false, "md5_digest": "472e50222294759445aca09e604cdf59", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12038, "upload_time": "2012-01-08T22:10:14", "url": "https://files.pythonhosted.org/packages/02/e4/8fb5ac3197781ace7410a1447f48b527b9d5899ecd8a8265f47e2a2c3c0b/micromongo-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "b06a8718b3ea2d4af1e675e3965304a0", "sha256": "bff534e5ee415d891c229de867bde004e4af736a6c7ab49e7ec009577c7b6416" }, "downloads": -1, "filename": "micromongo-0.1.4.tar.gz", "has_sig": false, "md5_digest": "b06a8718b3ea2d4af1e675e3965304a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12053, "upload_time": "2012-01-15T17:46:37", "url": "https://files.pythonhosted.org/packages/98/6b/e8e123c735c985ed7f216a227eb15d09302cd140caa53e3accffc5932b27/micromongo-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b06a8718b3ea2d4af1e675e3965304a0", "sha256": "bff534e5ee415d891c229de867bde004e4af736a6c7ab49e7ec009577c7b6416" }, "downloads": -1, "filename": "micromongo-0.1.4.tar.gz", "has_sig": false, "md5_digest": "b06a8718b3ea2d4af1e675e3965304a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12053, "upload_time": "2012-01-15T17:46:37", "url": "https://files.pythonhosted.org/packages/98/6b/e8e123c735c985ed7f216a227eb15d09302cd140caa53e3accffc5932b27/micromongo-0.1.4.tar.gz" } ] }