A modern async python3 web framework
Project description
# Albatross
I wanted to see how simple it is to make an modern async web framework. (python3.5 only)
It turns out - it's dead simple.
```python
from albatross import Server
import asyncio
class Handler:
async def on_get(self, req, res):
await asyncio.sleep(0.1)
res.write('Hello, %s' % req.args['name'])
app = Server()
app.add_route('/(?P<name>[a-z]+)', Handler())
app.serve()
```
## Install
pip3 install albatross3
## Usage
Create an app. Create handlers that have async functions `on_get`, `on_post`, etc. Call add_route with regex-based routes
to add the handlers. Call `app.serve()`.
See `examples/` for examples.
## Features
- You can read the entire codebase in about 10 minutes.
There are probably many non-HTTP-compliant and subtle bugs as a consequence, but
it works for building simple or moderately complex servers right now!
- It's natively async
- This works with the awesome `uvloop` project. It doesn't yet work with pypy3, because they don't support python3.5.
Let's make it happen!
## Framework
The entire framework is 4 files at the moment:
- status_codes.py - blatantly copied from Falcon, because they did such a great job with that framework.
- server.py - the web server you instantiate, add routes & handlers, and allows you to serve
- request.py - a web request object
- response.py - a web response object
Each of those is less than 100 lines or so.
## Current Gotchas
- Be careful with casing on HTTP headers. The framework should force standardization, but currently they are case-sensitive.
## Todo
- tests: tests are a good idea. I should write some.
I wanted to see how simple it is to make an modern async web framework. (python3.5 only)
It turns out - it's dead simple.
```python
from albatross import Server
import asyncio
class Handler:
async def on_get(self, req, res):
await asyncio.sleep(0.1)
res.write('Hello, %s' % req.args['name'])
app = Server()
app.add_route('/(?P<name>[a-z]+)', Handler())
app.serve()
```
## Install
pip3 install albatross3
## Usage
Create an app. Create handlers that have async functions `on_get`, `on_post`, etc. Call add_route with regex-based routes
to add the handlers. Call `app.serve()`.
See `examples/` for examples.
## Features
- You can read the entire codebase in about 10 minutes.
There are probably many non-HTTP-compliant and subtle bugs as a consequence, but
it works for building simple or moderately complex servers right now!
- It's natively async
- This works with the awesome `uvloop` project. It doesn't yet work with pypy3, because they don't support python3.5.
Let's make it happen!
## Framework
The entire framework is 4 files at the moment:
- status_codes.py - blatantly copied from Falcon, because they did such a great job with that framework.
- server.py - the web server you instantiate, add routes & handlers, and allows you to serve
- request.py - a web request object
- response.py - a web response object
Each of those is less than 100 lines or so.
## Current Gotchas
- Be careful with casing on HTTP headers. The framework should force standardization, but currently they are case-sensitive.
## Todo
- tests: tests are a good idea. I should write some.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
albatross3-0.1.5.tar.gz
(7.2 kB
view hashes)
Built Distribution
albatross3-0.1.5-py3-none-any.whl
(10.0 kB
view hashes)
Close
Hashes for albatross3-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002256ced8db912fda40d74ec3e50d9cbc9e8e0a6cb6261bc22f257f51c2ba90 |
|
MD5 | f47c41255a267b9cfb5a4848d7f3bb92 |
|
BLAKE2b-256 | ebf66602a25f069634e71ff5c5a92ca3eebea7aeb13d903bef603b78fa38be27 |