This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

This project is a fork of official project* with some new features.

Booby is a standalone data modeling and validation library written in Python. Booby is under active development (visit this blog post for more info and the roadmap) and licensed under the Apache2 license, so feel free to contribute and report errors and suggestions.

Usage

See the sample code below to get an idea of the main features.

from booby import Model, fields


class Token(Model):
    key = fields.String()
    secret = fields.String()


class Address(Model):
    line_1 = fields.String()
    line_2 = fields.String()


class User(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'}
    ]
)

if jack.is_valid:
    print jack.to_json(indent=2)
else:
    print json.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
    }
  ]
}

Advanced

Booby 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:

from booby import Model, fields

class User(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:

> python example.py
Traceback (most recent call last):
  File "/Users/Dani/Projects/apitest/apitest/actions/analyze/console.py", line 39, in launch_analyze_in_console
    postman_parser(json_info)
  File "/Users/Dani/Projects/apitest/apitest/actions/analyze/postman.py", line 52, in postman_parser
    end_points=postman_info.get("item")))
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 108, in __init__
    self._update(kwargs)
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 163, in _update
    self[k] = v
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 150, in __setitem__
    setattr(self, k, v)
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/fields.py", line 317, in __set__
    value = self._resolve(value)
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/fields.py", line 325, in _resolve
    item = self.model(**item)
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 108, in __init__
    self._update(kwargs)
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 163, in _update
    self[k] = v
  File "/Users/Dani/.virtualenvs/apitest/lib/python3.5/site-packages/booby/models.py", line 148, in __setitem__

booby.errors.FieldError: address

If you want Booby ignore these properties that don’t understand, you can define the Model class adding the property __ignore_missing__

from booby import Model, fields

class User(Model):
    __ignore_missing__ = True

    login = fields.String(required=True)
    name = fields.String()

input_info = dict(login="john", name="doe", address="other field")

jack = User(**input_info)

Installation

You can install the last stable release of Booby from PyPI using pip or easy_install.

$ pip install booby

Also you can install the latest sources from Github.

$ pip install -e git+git://github.com/jaimegildesagredo/booby.git#egg=booby

Tests

To run the Booby test suite you should install the development requirements and then run nosetests.

$ pip install -r test-requirements.txt
$ nosetests tests/unit
$ nosetests tests/integration

Changes

See Changes.

Release History

Release History

0.8.3.post1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.2.post3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.2.post2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.2.post1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.8.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
booby-ng-0.8.3.post1.tar.gz (14.4 kB) Copy SHA256 Checksum SHA256 Source Sep 21, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting