{ "info": { "author": "peatiscoding", "author_email": "freeuxer@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python :: 2.7", "Topic :: Database", "Topic :: Software Development :: Libraries" ], "description": "pymongo-document-modeling\n=========================\n\nCreate data model backed with pymongo called: Document which have\nability of polymorphism, and inheritance.\n\nFeature\n-------\n\nThis document modeling library designed with OOP as a goal. Therefore it\ncan associate field, and inherit it to its subclasses.\n\nInstallation\n------------\n\nBegin with installation\n\n.. code:: python\n\n > pip install pymongo-document-modeling\n \nConfiguration\n-------------\n\nOnce you have installed ``pymongo-document-modeling`` module. Now you \ncan start configure your pymongo. To state the configuration file, first prepare your config.\n\nHere is a dirty example of configuration file.\n\n.. code:: python\n\n [default]\n connection_string = mongodb://localhost:27017/\n database_name = test_beds\n [test_data_pool]\n connection_string = mongodb://localhost:27017/\n database_name = test_data_pool\n\nFor more advance cases. You can actually specify many connection sections as you want \n(But ``default`` section is required).\n\nNow let the system know where your configuration file is. To do this, call ``conf.update_config()`` \nbefore your declare your first class.\n\n.. code:: python\n\n from pymongo_document import conf\n \n # example a - specify the file\n conf.update_config('conf/my-config.ini') # read config from os.path.getcwd() + 'conf/my-config.ini'\n # example b - specify directory (default config file name will be assumed).\n conf.update_config('conf/') # read config from os.path.getcwd() + 'conf/pymongo-connectors.ini'\n \nLastly, within your model, you can reference this connector name. If omitted ``default`` will be used. \n(See first example in Quick start section's ``Meta`` class).\n\n*Note* If ``conf.update_config()`` never get invoked, this default configuration will be assumed.\n\n.. code:: python\n \n [default]\n connection_string = mongodb://localhost:27017/\n database_name = default_database\n\nQuick Start\n-----------\n\nLearn by example is simplest, and fastest. Here are some quick and dirty\nsimple class examples.\n\n.. code:: python\n \n from pymongo_document import documents as doc # Import library module as \"doc\"\n\n class SimpleDocument(doc.Doc):\n int_val = doc.FieldNumeric()\n str_val = doc.FieldString(default=\"default_value_of_string\")\n\n class Meta:\n collection_name = \"simple_document\" # Special class to annotate the document name to be saved.\n connection_name = \"test_data_pool\" # Explicitly state connection_name, (If omitted, 'default' will be used)\n\nLoad and Save is as simple as Django\u2019s Model.\n\n.. code:: python\n\n d = SimpleDocument()\n d.int_val = 500\n d.save() # document is saved to your mongodb\n\n loaded = SimpleDocument(d.object_id)\n print d.int_val # 500\n print d.str_Val # default_value_of_string\n print d.object_id # auto generated bson.ObjectId\n\nFor more complex classes, you can inherit from existing class, override\nexisting fields.\n\n.. code:: python\n\n class ABitComplexDocument(SimpleDocument): # Extend existing model\n int_val_2 = doc.FieldNumeric(none=False) # Add new field\n str_val = doc.FieldString(default=\"default_value_changed\") # Override existing model's field\n\n class Meta:\n collection_name = \":complex_1\" # use ':' to annotate the system to let this data model shared parent's collection\n\nMongo doesn\u2019t have join, but we could establish connection between\ncollection. We facilitate this by nesting them in a list of documents.\n\n.. code:: python\n\n class HolderOfSimpleDocuments(doc.Doc):\n list_of_docs = doc.FieldList(doc.FieldDoc(SimpleDocument))\n\n class Meta:\n collection_name = \"document_holders\"\n\nThere are many more type of example, please see the complete list of\ndocumentation below.\n\nReferences\n==========\n\nDocument Object\n---------------\n\nDocument is designed with ``django`` model in mind. With help of special\n``Meta`` class, we can beautifully annotate the document with\n``indices``, ``connection_name``, ``collection_name`` and more.\n\nTo create a new document, you can simply start by extending ``Doc`` class.\n\n.. code:: python\n\n from pymongo_document import documents as doc\n\n class MySimpleDoc(doc.Doc):\n # Define fields here\n name = doc.FieldString(max_length=30, none=False)\n\n class Meta:\n collection_name = 'my_simple_doc'\n\nWith this code, ``MySimpleDoc`` will be created when this module is\nimported. This ``MySimpleDoc`` will have exactly 2 fields (not 1).\n\n1. Field ``name`` is created as a string field, cannot be ``None``, and\n text length must not exceeds 30.\n2. Field ``object_id`` is also (automatically) created by inherit it\n from ``doc.Doc`` class. You can explicitly override this field, by\n redeclare the field with exact same name. The type can be totally\n different.\n\n.. code:: python\n\n o = MySimpleDoc() # Create a new MySimpleDoc instance\n o.save() # Error thrown, 'name' is required.\n o.name = 1 # Error thrown, in correct type, 'basestring' is required.\n o.name = 'peatiscoding' # Set name\n o.save() # Successfully saved to collection 'my_simple_doc'\n\nDocument.manager\n----------------\n\nAll documents class will be equipped with ``manager`` object (``pymongo_document.Docs`` class).\n``manager`` is just like ``objects`` in Django's Model's manager. Allows user to ``find`` , ``update``,\nor ``delete`` documents.\n\nFind API\n~~~~~~~~\n\nTo make things easy, I've decided to use pymongo existing ``find`` api. For complete doc\nsee `find() document`_. pymongo collection's ``find()`` method normally return ``dict`` as output.\nInstead of returning simple ``dict``, the ``Document`` instance will be returned.\n\n.. _find() document: http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.find\n\n.. code:: python\n\n o = MySimpleDoc()\n o.save()\n\n cursor = MySimpleDoc.manager.find().sort('_id') # use Cursor's method as pymongo did.\n for a in cursor:\n print \"%s\" % a.object_id # cursor returned objects is now already inflated as Document.\n\nFieldSpecAware Object\n---------------------\n\n``Doc`` class is inherited from ``FieldSpecAware`` class. ``FieldSpecAware`` taken care \nof ``Field`` detection, and overseer them in translating from python object, to document \n(saving format for mongodb). \n\nNormally you will use ``FieldSpecAware`` with ``FieldNested``. So that you can define a \ndict within another document. See @FieldNested for more information.\n\nFields\n------\n\nEvery field are customisable via the use of ``**kwargs`` of which each options will be provided in the\nsample per each individual fields below.\n\nIn addition, every field is compatible with assigning its own ``validator`` as well. To add your own\nvalidators. Create a field, then specific validators keyword argument in field creation.\n\nValidator can be defined in 2 styles.\n\n* ``Callable`` - if you supplied validators as a simple callable, then you are responsible to raise a proper ``FieldValidationError`` manually.\n* ``(Callable, basestring)`` - if ``callable`` returns True, ``basestring`` will be raised as an Error message.\n\nHere is an example.\n\n.. code:: python\n\n def in_the_past_or_throw(value, name):\n if isinstance(value, datetime) and value < datetime.now():\n return\n raise err.FieldValidationError(value, 'Value must be past', name)\n\n class TestMeDocument(doc.Doc):\n positive_number = doc.FieldNumeric(validators=[(lambda v: v < 0, 'positive number is required')])\n even_number = doc.FieldNumeric(validators=[(lambda v: v % 2 == 1, 'even number only')])\n negative_odd_number = doc.FieldNumeric(validators=[\n (lambda v: v > 0, 'negative number is required'),\n (lambda v: v % 2 == 0, 'odd number is required')\n ])\n custom_value = doc.FieldDateTime(validators=[in_the_past_or_throw]) # Callable style\n\nBy assigning incorrect value ``FieldValidationError`` will be raised.\n\nFieldObjectId\n~~~~~~~~~~~~~\n\nUse this field to store any ``ObjectId``. But If you would like to store\nanother document reference. Try ``FieldDoc`` or ``FieldAnyDoc`` instead.\n\n*Usage*\n\n.. code:: python\n\n class SimpleDocument(doc.Doc):\n oid = doc.FieldObjectId()\n\nObjectId field accepts ``bson.ObjectId`` instance, or ``bson.ObjectId``\ncompatible string (24 alphanumeric string).\n\n*Note* that normally if you inherit from ``Doc`` you will automatically\nget ``object_id`` field for free.\n\nFieldNumeric\n~~~~~~~~~~~~\n\nUse this field to store any numeric numbers.\n\n*Usage*\n\n.. code:: python\n\n class SimpleDocument(doc.Doc):\n VALUE_A = 1\n VALUE_B = 2\n VALUE_C = 3\n VALUES = (\n (VALUE_A, '1st value'),\n (VALUE_B, '2nd value'),\n (VALUE_C, '3rd value')\n )\n \n amount1 = doc.FieldNumeric(default=3, max_value=50, min_value=10)\n amount2 = doc.FieldNumeric(max_value=40, none=False)\n amount3 = doc.FieldNumeric() # no max, no min, can be None, no default\n amount4 = doc.FieldNumeric(choices=VALUES)\n\n* ``max_value`` - (numeric) set upper bound of field. Default is None (no upper bound).\n* ``min_value`` - (numeric) set lower bound of field. Default is None (no lower bound).\n* ``default`` - (numeric) set a default value for this field. Default is None.\n* ``none`` - (boolean) set to False to prohibit None value for this field. Default is True.\n* ``choices`` - (tuple, list) set possible values for the field. Default is None.\n\nFieldString\n~~~~~~~~~~~\n\nUse this file to store any ``basestring`` instance.\n\n*Usage*\n\n.. code:: python\n\n class SimpleDocument(doc.Doc):\n VALUE_A = 'A'\n VALUE_B = 'B'\n VALUE_C = 'C'\n VAULES = (\n (VALUE_A, 'A description'),\n (VALUE_B, 'B description'),\n (VALUE_C, 'C description'),\n )\n str_value = doc.FieldNumeric(default=\"default_string\", max_length=10)\n fixed_length_str_value = doc.FieldString(fixed_length=2)\n fixed_choices_str_value = doc.FieldString(choices=VALUES, default=VALUE_A)\n fixed_pattern_str_value = doc.FieldString(pattern=r'[a-z]{2}\\d{5}3-[A-Z]{2}')\n\n* ``pattern`` - (SRE_Pattern|regex pattern string) set a required pattern for input string. Default is None.\n* ``max_length`` - (numeric) set maximum character count. Default is None (no upper bound).\n* ``fix_length`` - (numeric) set constant character count. Default is None (no upper bound).\n* ``default`` - (numeric) set a default value for this field. Default is None.\n* ``none`` - (boolean) set to False to prohibit None value for this field. Default is True.\n* ``choices`` - (tuple, list) set possible values for the field. Default is None.\n \n\nFieldDict\n~~~~~~~~~\n\nUse this field to store complete any python dict without schema.\n\n*Usage*\n\n.. code:: python\n\n class SimpleDocument(doc.Doc):\n data = doc.FieldDict()\n\n* ``default`` - (dict) set a default value for this field. Default is None.\n* ``none`` - (boolean) set to False to prohibit None value for this field. Default is True.\n\n\nFieldTuple\n\nUse this field to store a FieldSpec value that obligated by each rule based on position on the list.\n\n*Usage*\n\n.. code:: python\n\n class TupleFieldDocument(doc.Doc):\n data = doc.FieldTuple(doc.FieldNumeric(), doc.FieldString(), doc.FieldNumeric())\n\n* ``default`` - (tuple) set a default value for this field. Default is None.\n* ``none`` - (boolean) set to False to prohibit Nont value for this field. Default is True.\n\nUnlike ``FieldList``, ``FieldTuple`` constructor accept ``*args`` as argument of ``FieldSpec``. Each ``FieldSpec``\ncorrespond to Field specification for each element on the tuple respectively.\n\nTherefore ``FieldTuple`` assignment required an exact tuple size to the ``FieldSpec`` provided in constructor.\n\n.. code:: python\n\n o = TupleFieldDocument()\n o.data = (12, 'test', 12) # this is okay\n o.data = (12, 'test') # raise doc.FieldValidationError invalid tuple size\n o.data = ('test', 24, 45) # raise doc.FieldValidationError index 1 should be integer, index 2 should be text", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/peatiscoding/pymongo-document-modeling", "keywords": "pymongo,database,mongodb,modeling", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "pymongo-document-modeling", "package_url": "https://pypi.org/project/pymongo-document-modeling/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pymongo-document-modeling/", "project_urls": { "Homepage": "https://github.com/peatiscoding/pymongo-document-modeling" }, "release_url": "https://pypi.org/project/pymongo-document-modeling/0.9.2.dev1/", "requires_dist": null, "requires_python": "", "summary": "PyMongo data modeling library", "version": "0.9.2.dev1" }, "last_serial": 2243992, "releases": { "0.9.0.dev8": [ { "comment_text": "", "digests": { "md5": "0cfeeea2a85c8bcb984dbdcfb5641a68", "sha256": "1f2f94af44de6f5468f2e8d670e2fff1d7a49f67f0ed0fda52b0ce3359611eaf" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.0.dev8.tar.gz", "has_sig": false, "md5_digest": "0cfeeea2a85c8bcb984dbdcfb5641a68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15941, "upload_time": "2015-12-06T08:01:21", "url": "https://files.pythonhosted.org/packages/86/15/7d48cd6065eeb7cc2a06781eb6b5cb44bb8df2fa88f37b1e19862b48644c/pymongo-document-modeling-0.9.0.dev8.tar.gz" } ], "0.9.1.dev1": [ { "comment_text": "", "digests": { "md5": "991cc4b0b0a9cf82ffb1b4aa3ec60d31", "sha256": "ef3aae221661729e566c72769cf3a9a871af2a4b5ef2e64ec47c6f3626a11713" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev1.tar.gz", "has_sig": false, "md5_digest": "991cc4b0b0a9cf82ffb1b4aa3ec60d31", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16732, "upload_time": "2015-12-08T08:14:14", "url": "https://files.pythonhosted.org/packages/43/0c/f52a109c5275b7b45e14f32b6b11139f62095387fda6f0482463050bbfc7/pymongo-document-modeling-0.9.1.dev1.tar.gz" } ], "0.9.1.dev2": [ { "comment_text": "", "digests": { "md5": "a8df2e95e0ec9e2ea55e642a94e62dc7", "sha256": "6db5e679307a07bb36d23d5adc77cb93ebed2fcbde6ebef61cc40bdd7646371f" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev2.tar.gz", "has_sig": false, "md5_digest": "a8df2e95e0ec9e2ea55e642a94e62dc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17978, "upload_time": "2015-12-28T04:26:09", "url": "https://files.pythonhosted.org/packages/e0/01/1eadba9d4d1c9921e63ff435a66b5415a32e475617dcba4df3d8b1d6b4c9/pymongo-document-modeling-0.9.1.dev2.tar.gz" } ], "0.9.1.dev3": [ { "comment_text": "", "digests": { "md5": "4fa543e45a9d9ff4fdeefa470e684b87", "sha256": "fa663759295eb1e323b5899a02bb429f8d954a52e18bbb1231f78a58c842ee2a" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev3.tar.gz", "has_sig": false, "md5_digest": "4fa543e45a9d9ff4fdeefa470e684b87", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17986, "upload_time": "2015-12-29T01:32:40", "url": "https://files.pythonhosted.org/packages/7c/d9/8a8497d957e0e01432fe3caf244f81cb4b7df15429ebb096aaff19fbf6a8/pymongo-document-modeling-0.9.1.dev3.tar.gz" } ], "0.9.1.dev4": [ { "comment_text": "", "digests": { "md5": "721b3b38a5b1e64a8e2f6e63a4d13b07", "sha256": "9f5b3565c9d03c35d927b7cf301a447096801180175f1c838b0f3434b478c032" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev4.tar.gz", "has_sig": false, "md5_digest": "721b3b38a5b1e64a8e2f6e63a4d13b07", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18924, "upload_time": "2016-02-10T13:46:37", "url": "https://files.pythonhosted.org/packages/a2/09/eeea62295f72116cdd85d8f7a5a27dc76b12bbfc05393a20fbd4eaf036cd/pymongo-document-modeling-0.9.1.dev4.tar.gz" } ], "0.9.1.dev5": [ { "comment_text": "", "digests": { "md5": "787463fc9c1b98626af939cef06d6f43", "sha256": "b5b0c2918950a3ce712be3d1696f3a22d7ab750a258016ffda619ee12bddf7ec" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev5.tar.gz", "has_sig": false, "md5_digest": "787463fc9c1b98626af939cef06d6f43", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18947, "upload_time": "2016-05-24T13:34:11", "url": "https://files.pythonhosted.org/packages/71/d2/252ee75ddd752a7965c82fd92bae7d7a4af0183fcc1a4de4c3170ca01468/pymongo-document-modeling-0.9.1.dev5.tar.gz" } ], "0.9.1.dev6": [ { "comment_text": "", "digests": { "md5": "b4a891df6696dcc0e0f3e57c76d4bcce", "sha256": "aaffa736099166790d54155d3b1e95f846e5b1cdfd5670c2d7e247d0ebfac21c" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.1.dev6.tar.gz", "has_sig": false, "md5_digest": "b4a891df6696dcc0e0f3e57c76d4bcce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18968, "upload_time": "2016-05-26T07:06:09", "url": "https://files.pythonhosted.org/packages/1e/ae/71caad2a226be6080bd8a54eb7e5dc78534b3e9479defb8d3e76ca78f614/pymongo-document-modeling-0.9.1.dev6.tar.gz" } ], "0.9.2.dev1": [ { "comment_text": "", "digests": { "md5": "c493a9cb30ede0b8a41d19d826ee394f", "sha256": "149de2d667e17acc9b7873a52ec4b4a705a0660f5fd5bb188bee696d8d64f81e" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.2.dev1.tar.gz", "has_sig": false, "md5_digest": "c493a9cb30ede0b8a41d19d826ee394f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19012, "upload_time": "2016-07-26T05:58:09", "url": "https://files.pythonhosted.org/packages/8a/8d/840f4231b85aecbe14286c690ecbcf973d4a88add08df272a02d70965679/pymongo-document-modeling-0.9.2.dev1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c493a9cb30ede0b8a41d19d826ee394f", "sha256": "149de2d667e17acc9b7873a52ec4b4a705a0660f5fd5bb188bee696d8d64f81e" }, "downloads": -1, "filename": "pymongo-document-modeling-0.9.2.dev1.tar.gz", "has_sig": false, "md5_digest": "c493a9cb30ede0b8a41d19d826ee394f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19012, "upload_time": "2016-07-26T05:58:09", "url": "https://files.pythonhosted.org/packages/8a/8d/840f4231b85aecbe14286c690ecbcf973d4a88add08df272a02d70965679/pymongo-document-modeling-0.9.2.dev1.tar.gz" } ] }