Package: booby-ng
This project is a fork of official project*with some new features.Booby is a standalone datamodelingandvalidationlibrary written in Python. Booby is under active development (visitthis blog postfor more info and the roadmap) and licensed under theApache2 license, so feel free tocontributeandreport errors and suggestions.UsageSee the sample code below to get an idea of the main features.fromboobyimportModel,fieldsclassToken(Model):key=fields.String()secret=fields.String()classAddress(Model):line_1=fields.String()line_2=fields.String()classUser(Model):login=fields.String(required=True)name=fields.String()email=fields.Email()site=fields.URL()token=fields.Embedded(Token,required=True)addresses=fields.Collection(Address)jack=User(login='jack',name='Jack',email='jack@example.com',url='http://mysite.com',token={'key':'vs7dfxxx','secret':'ds5ds4xxx'},addresses=[{'line_1':'Main Street'},{'line_1':'Main St'}])ifjack.is_valid:printjack.to_json(indent=2)else:printjson.dumps(dict(jack.validation_errors)){"email":"jack@example.com","url":"http://mysite.com","login":"jack","token":{"secret":"ds5ds4xxx","key":"vs7dfxxx"},"name":"Jack","addresses":[{"line_1":"Main St","line_2":null},{"line_1":"Main Street","line_2":null}]}AdvancedBooby raises when you try to pass a property as input dict thata not exist as property. It’s very annoying when you want to pass a big JSON and want that Booby take only their parameters that it understand.For example:fromboobyimportModel,fieldsclassUser(Model):login=fields.String(required=True)name=fields.String()input_info=dict(login="john",name="doe",address="other field")jack=User(**input_info)This code raise the exception:>pythonexample.pyTraceback(mostrecentcalllast):File"/Users/Dani/Projects/apitest/apitest/actions/analyze/console.py",line39,inlaunch_analyze_in_consolepostman_parser(json_info)File"/Users/Dani/Projects/apitest/apitest/actions/analyze/postman.py",line52,inpostman_parserend_points=postman_info.get("item")))File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line108,in__init__self._update(kwargs)File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line163,in_updateself[k]=vFile"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line150,in__setitem__setattr(self,k,v)File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/fields.py",line317,in__set__value=self._resolve(value)File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/fields.py",line325,in_resolveitem=self.model(**item)File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line108,in__init__self._update(kwargs)File"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line163,in_updateself[k]=vFile"/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py",line148,in__setitem__booby.errors.FieldError:addressIf you want Booby ignore these properties that don’t understand, you can define the Model class adding the property__ignore_missing__fromboobyimportModel,fieldsclassUser(Model):__ignore_missing__=Truelogin=fields.String(required=True)name=fields.String()input_info=dict(login="john",name="doe",address="other field")jack=User(**input_info)InstallationYou can install the last stable release of Booby from PyPI using pip or easy_install.$pipinstallboobyAlso you can install the latest sources from Github.$pipinstall-egit+git://github.com/jaimegildesagredo/booby.git#egg=boobyTestsTo run the Booby test suite you should install the development requirements and then run nosetests.$pipinstall-rtest-requirements.txt$noseteststests/unit$noseteststests/integrationChangesSeeChanges.