SStatic file support for bareasgi
Project description
# bareasgi-static
Static file support for [bareASGI](http://github.com/rob-blackbourn/bareasgi) (read the [documentation](https://bareasgi-static.readthedocs.io/en/latest/))
## 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_response
here = os.path.abspath(os.path.dirname(__file__))
async def http_request_callback(scope, info, matches, content):
return await file_response(scope, 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_provider
here = 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)
```
Static file support for [bareASGI](http://github.com/rob-blackbourn/bareasgi) (read the [documentation](https://bareasgi-static.readthedocs.io/en/latest/))
## 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_response
here = os.path.abspath(os.path.dirname(__file__))
async def http_request_callback(scope, info, matches, content):
return await file_response(scope, 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_provider
here = 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)
```
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
bareasgi_static-1.0.0.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for bareasgi_static-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 735ea73205a964089373a8f177d0d51993a5f9d4e46cb36c3bea5fcb98a9375d |
|
MD5 | 527940225dde181bd3caf40586e82c77 |
|
BLAKE2b-256 | 322094ea0c9a91ca5dbbbbea736822e63082beab9032e44ec0b6246130ad87e1 |