ned Intervert, Energy) Part time postdoc researcher @ TUM (http://neurita.github.io/) Python conference organizer EuroPython Society Board PySS, San Sebastián, Spain PyMunich/PyconWeb 2
weird_salute(first_name: hug.types.text, age: int): if age > 80: return f"Hi {first_name}, you look so young today!" return f"Hi {first_name}!" Many built-in options Custom types Marshmallow integration 8
# is here automatically, without needing to be passed in Built-in: timer , module , api_version , api , documentation , session , user ... Custom directives, e.g., client_type 9
import authentication from books.exceptions import RecordNotFound from books.services.book import DeviceService @api.urls('/books') class BooksController(): @api.get('', requires=[authentication(),]) def index(self, user: hug.directives.user): """Return the list of available books""" books = BooksService.where(user_id=user.id).all() return IndexPresenter(books) ... 17
hug.directives.user): """Return a book matching the id""" book = BooksService.find(book_id) if not book: raise RecordNotFound('Resource not found') if BooksService.is_my_book(book.id, user.id): return OwnedBookPresenter(book) return BookPresenter(book) 18
import crud_stub_controller class _APIProvider: """ Base cactus test class to provide API setup and teardown. """ @classmethod def setup(cls): api.extend(crud_stub_controller) @classmethod def teardown(cls): "Remove endpoints that start with '/test' in api.http.routes." 31