Minimalistic async HTTP server
Project description
# Minimalistic async HTTP server
This framework was inspired by [sanic](https://github.com/huge-success/sanic) framework.
This framework designed to be fast and be capable to start within 1.5 seconds at max (see [cold start problem](https://medium.com/@denismakogon/investigating-pythons-performance-issue-cold-start-8ebf443a8a20)).
## How to install
```bash
pip install async-http-minimal
```
## Example
```python
import asyncio
import socket
from async_http import app
from async_http import router
from async_http import response
async def hello(request):
return response.text("hello-world!")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("localhost", 9999))
rtr = router.Router()
rtr.add("/hello", frozenset({"GET"}), hello)
srv = app.AsyncHTTPServer(name="hello-world-server", router=rtr)
start_serving, run_forever = srv.run(sock=sock, loop=loop)
start_serving()
# here you can do some additional operations before starting an infinite serving
# can be helpful for unix sockets, etc.
run_forever()
```
This framework was inspired by [sanic](https://github.com/huge-success/sanic) framework.
This framework designed to be fast and be capable to start within 1.5 seconds at max (see [cold start problem](https://medium.com/@denismakogon/investigating-pythons-performance-issue-cold-start-8ebf443a8a20)).
## How to install
```bash
pip install async-http-minimal
```
## Example
```python
import asyncio
import socket
from async_http import app
from async_http import router
from async_http import response
async def hello(request):
return response.text("hello-world!")
if __name__ == "__main__":
loop = asyncio.get_event_loop()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("localhost", 9999))
rtr = router.Router()
rtr.add("/hello", frozenset({"GET"}), hello)
srv = app.AsyncHTTPServer(name="hello-world-server", router=rtr)
start_serving, run_forever = srv.run(sock=sock, loop=loop)
start_serving()
# here you can do some additional operations before starting an infinite serving
# can be helpful for unix sockets, etc.
run_forever()
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async-http-minimal-0.0.4.tar.gz
(23.6 kB
view hashes)
Built Distribution
Close
Hashes for async_http_minimal-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8edc134357feef065093eeb6a40895f6d00fa2111c59a418c91c8512cb17fa16 |
|
MD5 | 7cb18093a1d75ce4961234cfdefdd0ac |
|
BLAKE2b-256 | a925be966114b2848bf7e3d3fe497906919433fc0143fa1bfeca9f8936ff0c97 |