https://github.com/chimpler/pytcher
Routing web tree framework for python
https://github.com/chimpler/pytcher
python3 rest-api web
Last synced: 7 months ago
JSON representation
Routing web tree framework for python
- Host: GitHub
- URL: https://github.com/chimpler/pytcher
- Owner: chimpler
- License: apache-2.0
- Created: 2019-03-03T03:50:52.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T19:32:46.000Z (almost 5 years ago)
- Last Synced: 2025-07-02T05:49:58.311Z (10 months ago)
- Topics: python3, rest-api, web
- Language: Python
- Homepage: https://chimpler.github.io/pytcher/
- Size: 833 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.python.org/pypi/pytcher)
[](https://pypi.python.org/pypi/pytcher/)
[](https://travis-ci.org/chimpler/pytcher)
[](https://pypistats.org/packages/pytcher)
[](https://coveralls.io/github/chimpler/pytcher?branch=master)
[](https://pypi.python.org/pypi/pyhocon/)
[](https://requires.io/github/chimpler/pytcher/requirements/?branch=master)
### Pytcher
Pytcher is a REST micro-framework for Python 3 that relies on a routing tree
similar to [RODA](http://roda.jeremyevans.net/) in Ruby, [Akka HTTP](https://doc.akka.io/docs/akka-http/current/index.html) in Scala or [Javalin](https://javalin.io/) 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:
```python
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/ 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()
```