Skip to content

cbourget/annotype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Annotype: Python 3 annotations and marshmallow

Annotype combines Python 3 annotations and Marshmallow for powerful validation of function arguments.

from annotype import annotyped
from marshmallow import (
    Schema,
    fields
)


class PersonSchema(Schema):
    firstname = fields.Str(required=True)
    lastname = fields.Str(required=True)

@annotyped()
def salute(person: PersonSchema):
    print 'Hello {} {}'.format(person['firstname'], person['lastname'])

person = dict(firstname='John')

# This will raise a ValidationError because lastname is not defined
salute(person)

@annotyped()
def welcome(firstname: fields.Str(), lastname: fields.Str()):
    print 'Welcome {} {}'.format(firstname, lastname)

# This will also raise a ValidationError because lastname is not a string
welcome('Jane', 1)

In short, annotype allows you to validate data using the powerful marshmallow library and the Python 3 annotations.

Get It Now

$ pip install -U annotype

Documentation

See marshmallow documentation available here http://marshmallow.readthedocs.io/ .

Requirements

  • Python >= 3.4
  • marshmallow >= 3.0.0

License

MIT licensed. See the bundled LICENSE file for more details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages