Convenient, but not fast
Project description
starlette-dataframe-response
Convenient, but not fast.
Resources:
Installation
$ pip install starlette-dataframe-response
Requirements
Python 3.7+
Dependencies
- starlette
- pandas
- (vega_datasets)
- (magicalimport)
Example
import pandas as pd
from starlette.requests import Request
from starlette_dataframe_response import DataFrameResponse, guess_media_type
async def get_dataset(request: Request):
df: DataFrame = pd.read_csv("<some dataset>.csv")
return DataFrameResponse(df, media_type=guess_media_type(request))
app = Starlette(
debug=True,
routes=[
Route("/dataset/<some dataset>", get_dataset),
],
)
Then, supporting the request following.
# return dataset as json (orient=records)
GET /dataset/<some dataset>
# return dataset as csv
GET /dataset/<some dataset>?format=csv
# return dataset as markdown
GET /dataset/<some dataset>?format=markdown
# return dataset as html
GET /dataset/<some dataset>?format=html
If you want to customize the JSON response.
# use orient="columns"
DataFrameResponse(df, media_type=guess_media_type(request), to_json_orient="columns")
Or, if the response is created by DataFrameResponse.from_request(request, df), it is also OK.
$ use orient="columns"
GET /dataset/<some dataset>?to_json_orient=columns
python -m starlette_dataframe_response.distribute
And It also includes examples using vega-datasets.
$ python -m starlette_dataframe_response.distribute --port 8888
(with httpie)
$ http :8888/
$ http :8888/iris
$ http :8888/cars
$ http :8888/iris format==csv
$ http :8888/iris/columns
$ http :8888/iris/describe
$ http :8888/iris/groupby/species/aggs/sepalWidth
$ http :8888/iris/groupby/species/aggs/sepalWidth fn==min fn==max fn==count fn==mean fn==std
$ http :8888/iris/groupby/species/aggs/sepalWidth,sepalLength
Or if you want to see an example using a custom data, in above included app examples/01data-provider/
Contribution
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file starlette-dataframe-response-0.0.0.tar.gz.
File metadata
- Download URL: starlette-dataframe-response-0.0.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac422c3b0b611c449f191cb8cb8c5fc765be41668eb5f7394da18cf17cf57ca2
|
|
| MD5 |
ae875ae8c5c22aaf8628bab077ecca15
|
|
| BLAKE2b-256 |
2ed08f38d127202063caf3ed1c400cbb0c4f694cda7d0b4379ef90e5b1ead437
|
File details
Details for the file starlette_dataframe_response-0.0.0-py3-none-any.whl.
File metadata
- Download URL: starlette_dataframe_response-0.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcfc481859728a915f1db0fe85f6624dc3c3c6e8181ba9e9df6b58107efd197d
|
|
| MD5 |
12c7fdd686ff508db6dcf01ab131b24d
|
|
| BLAKE2b-256 |
37e23531fdae8ae996bbf04818361ab38962d5dac4946c68a995106633f054c5
|