Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rob-blackbourn/bareasgi-static
Static file support for bareasgi
https://github.com/rob-blackbourn/bareasgi-static
asgi asyncio bareasgi python static-files web
Last synced: about 1 month ago
JSON representation
Static file support for bareasgi
- Host: GitHub
- URL: https://github.com/rob-blackbourn/bareasgi-static
- Owner: rob-blackbourn
- License: apache-2.0
- Created: 2019-01-25T10:23:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-08-23T12:30:57.000Z (over 2 years ago)
- Last Synced: 2024-11-16T09:16:04.337Z (about 2 months ago)
- Topics: asgi, asyncio, bareasgi, python, static-files, web
- Language: Python
- Homepage: https://rob-blackbourn.github.io/bareASGI-static/
- Size: 1.45 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bareasgi-static
Static file support for [bareASGI](http://github.com/rob-blackbourn/bareasgi) (read the [documentation](https://rob-blackbourn.github.io/bareASGI-static/))
## Overview
This package provides support for serving static files to bareasgi.
## Usage
The following example serves a single file.
```python
import uvicorn
import os.path
from bareasgi import Application
from bareasgi_static import file_responsehere = os.path.abspath(os.path.dirname(__file__))
async def http_request_callback(request):
return await file_response(request, 200, os.path.join(here, 'file_stream.html'))app = Application()
app.http_router.add({'GET'}, '/example1', http_request_callback)uvicorn.run(app, port=9010)
```
The next example serves files below a given directory.
```python
import os.path
import uvicorn
from bareasgi import Application
from bareasgi_static import add_static_file_providerhere = os.path.abspath(os.path.dirname(__file__))
app = Application()
add_static_file_provider(app, os.path.join(here, simple_www), index_filename='index.html')uvicorn.run(app, port=9010)
```