Skip to content

Home

Pytcher is a REST micro-framework for Python 3 that relies on a routing tree similar to RODA in Ruby, Akka HTTP in Scala or Javalin in Java.

Features

  • Routing tree definition using with or for construction
  • Marshalling of Python objects (data classes, namedtuples, date, datetime, uuid, ...) that supports custom encoders
  • Unmarshalling of JSON to Python objects (data classes, namedtuples, date, datetime, uuid, ...) supporting typing (e.g., Dict[str, MyDataClass]) syntax and custom decoders.
  • Additional Routing decorators similar to Flask
  • Well scoped objects (no global variables)
  • Support for WSGI

Example of routing tree

# flake8: noqa: E999
import http

from pytcher import App, Integer, Request, route


class MyRouter(object):
    def __init__(self):
        self._items = ['pizza', 'cheese', 'ice-cream', 'butter']

    @route
    def route(self, r: Request):
        with r / 'items':
            with r.end:
                with r.get:
                    return self._items

                with r.post:
                    self._items.append(r.json)
                    return self._items[-1], http.HTTPStatus.CREATED

            with r / Integer as item_id:
                with r.get:
                    return self._items[item_id]

                with r.put:
                    self._items[item_id] = r.json
                    return self._items[item_id]

                with r.delete:
                    return self._items.pop(item_id)


app = App(MyRouter())

if __name__ == '__main__':
    app.start()