Package: simpledict
# simpledictMakes dict modeling easy for document based databases with minimal extra funcitonality* Permissioning* Embedded documents* Minimization of field names* Python Properties* One python file* Doctests - functionality is unit testedMissing features* No type system* No validation - up to you as the developer to add it.Other libraries that provide this functionality and more in python* [@j2lab's](http://twitter.com/j2labs) [DictShield](../../j2labs/DictShield) - great library with a type system and more# InstallationEasiest way to install is from PyPI```pip install simpledict```# ExampleCreating a simple model would involve creating a Class that subclasses simpledict.Dictionary```pythonimport simpledictclass Tweet(simpledict.Dictionary):field_user = "u"field_text = "t"field_count = "c"@propertydef character_count():return len(self.text)```and then to create the object:```pythontweet = Tweet(user="robspychala", text="hey everyone, what's cookin'?")```and to serialize to a dictionary```pythontweet_data = tweet.to_dict()```and of course to de-serialize back to an object, you'd```pythontweet = Tweet(**tweet_data)```## MinimizationIf you would like to minimize the field names to what is defined in the field_* values you pass in a minimize=True value to the to_dict() method```pythonminimized_tweet_data = tweet.to_dict(minimize=True)```and even if you have minimized data, you'd still be able to de-serialize it to a dictionary, ex:```pythonminimized_tweet = Tweet(**minimized_tweet_data)assert(tweet.title == minimized_tweet.title, tweet.user == minimized_tweet.user)```## PropertiesIf you would like to serialize properties```pythontweet_data_props = tweet.to_dict(properties={"count":None})assert(tweet_data_props["count"] == tweet.count)```## PermissioningAnd if you don't want to show the user, for whatever reason you'd use the omit_fields option```pythontweet_data = tweet.to_dict(omit_fields={"user":None})assert(not tweet_data.has_key("user"))```### Embedded Documents```pythonimport simpledictclass UserSettings(Dictionary):field_color = "c"field_size = "s"class User(Dictionary):field_settings = ("s", UserSettings)field_name = "n"user = User(name="Price", settings=UserSettings(color="purple", size="medium"))```### array of Embedded Documents```pythonimport simpledictclass EmbeddedInnerTest(simpledict.Dictionary):field_title = "t"field_page = "p"class EmbeddedTest(simpledict.Dictionary):field_title = "t"field_author = "a"field_toc = ("o", list, EmbeddedInnerTest)embedded_data = { 'title': "Embedded Title", 'author': "Embedded Author",'toc': [{'t':'Chapter One', 'p': 100}, {'t':'Chapter Two', 'p': 201}]}embedded_obj = EmbeddedTest(**embedded_data)embedded_obj.titleembedded_obj.authorembedded_obj.toc[0].titleembedded_obj.toc[1].titleembedded_obj.toc[1].page```### MongoDB example```pythonimport simpledictimport pymongofrom pymongo import Connectionconnection = Connection()db = connection.main_databaseclass User(simpledict.Dictionary):field_email = "e"field_password = "p"def insert(self):if not db or not self.email or not self.password:raise Exception()db[self.__class__.__name__.lower()].insert(self.to_dict(minimize=True))return self```and then to use this User class in your app and insert into a mongodb, it would involve```pythonentry = model.User(email="robspychala@gmail.com",password="mysekr3t").insert()entry_dict = entry.to_dict(minimize=False)self.response.out.write(json.dumps({'success': True, 'result': entry_dict},default=simpledict.json_date_handler))```# LicenseThe simpledict component is released under the MIT License.The MIT License (MIT) Copyright (c) 2012 Robert SpychalaPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.