Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rob-blackbourn/bareasgi
A lightweight Python ASGI web server framework
https://github.com/rob-blackbourn/bareasgi
asgi asyncio bareasgi http http-server http2 python sse web websocket
Last synced: 3 months ago
JSON representation
A lightweight Python ASGI web server framework
- Host: GitHub
- URL: https://github.com/rob-blackbourn/bareasgi
- Owner: rob-blackbourn
- License: apache-2.0
- Created: 2019-01-23T11:55:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-15T20:53:52.000Z (over 1 year ago)
- Last Synced: 2024-09-18T02:59:16.469Z (4 months ago)
- Topics: asgi, asyncio, bareasgi, http, http-server, http2, python, sse, web, websocket
- Language: Python
- Homepage: https://rob-blackbourn.github.io/bareASGI/
- Size: 1.9 MB
- Stars: 30
- Watchers: 5
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# bareASGI
A lightweight Python [ASGI](user-guide/asgi) web server framework
(read the [docs](https://rob-blackbourn.github.io/bareASGI/)).## Overview
This is a _bare_ ASGI web server framework. The goal is to provide
a minimal implementation, with other facilities (serving static files, CORS,
sessions, etc.) being implemented by optional packages.The framework is targeted at micro-services which require a light footprint
(in a container for example), or as a base for larger frameworks.Python 3.8+ is required.
## Optional Packages
- [bareASGI-cors](https://github.com/rob-blackbourn/bareASGI-cors) for cross origin resource sharing,
- [bareASGI-static](https://github.com/rob-blackbourn/bareASGI-static) for serving static files,
- [bareASGI-jinja2](https://github.com/rob-blackbourn/bareASGI-jinja2) for [Jinja2](https://github.com/pallets/jinja) template rendering,
- [bareASGI-graphql-next](https://github.com/rob-blackbourn/bareASGI-graphql-next) for [GraphQL](https://github.com/graphql-python/graphql-core) and [graphene](https://github.com/graphql-python/graphene),
- [bareASGI-rest](https://github.com/rob-blackbourn/bareASGI-rest) for REST support,
- [bareASGI-prometheus](https://github.com/rob-blackbourn/bareASGI-prometheus) for [prometheus](https://prometheus.io/) metrics,
- [bareASGI-session](https://github.com/rob-blackbourn/bareASGI-session) for sessions.## Functionality
The framework provides the basic functionality required for developing a web
application, including:- Http,
- WebSockets,
- Routing,
- Lifecycle,
- Middleware## Simple Server
Here is a simple server with a request handler that returns some text.
```python
import uvicorn
from bareasgi import Application, HttpRequest, HttpResponse, text_writerasync def example_handler(request: HttpRequest) -> HttpResponse:
return HttpResponse(
200,
[(b'content-type', b'text/plain')],
text_writer('This is not a test')
)app = Application()
app.http_router.add({'GET'}, '/', example_handler)uvicorn.run(app, port=9009)
```