Skip to content

chimpler/pytcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pypi Supported Python Versions Build Status Downloads Coverage Status License Requirements Status

Pytcher

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
  • Auto reload when code change is detected in debug mode

The routing tree can be defined as follows:

from pytcher import App, Request, Integer, route


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

    @route
    def route(self, r: Request):
        with r / 'items':  # if URL starts with /items
            with r.end:  # if there is nothing after /items
                with r.get:  # If it's a get request
                    return self._items

                with r.post:  # If request is a post request
                    self._items.append(r.json)
                    return self._items[-1]

            # If the URL is /items/<integer> then bind item_id to the integer
            with r / Integer() as item_id:
                with r.get:  # If the request is a get request
                    return self._items[item_id]

                with r.put:  # If the request is a put request
                    self._items[item_id] = r.json
                    return self._items[item_id]

                with r.delete:  # If the request is a delete request
                    return self._items.pop(item_id)


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

About

Routing web tree framework for python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages