Starlette-Views
starlette-views – A helper to make views faster with Starlette
Starlette-Views automatically converts views results into starlette.responses.Response objects.
Requirements
python >= 3.7
Installation
starlette-views should be installed using pip:
pip install starlette-views
Initialization
Just wrap your Starlette application into the views:
from starlette_views import Views
app = Starlette(...)
app = Views(app)
or you are able to import Starlette from the module (in this case you have nothing to setup more):
from starlette_views import Starlette
app = Starlette(...)
Quick Start
from starlette.applications import Starlette
from starlette.routing import Route
async def hello(request):
return 'Hello from Views!'
# Create Starlette Application
app = Starlette(routes=[
Route('/', hello)
])
# Enable the quick views
app = Views(app)
Then run the application…
$ uvicorn example:app
Open http://127.0.0.1:8000 and you will find the hello from the views.
Usage
async def render_json1(request):
"""Just return dictionary to make a JSON response."""
return {'any': 'value'}
async def render_json2(request):
"""List also works well."""
return [{'any': 'value'}]
async def render_json3(request):
"""Return a tuple to set HTTP status."""
return 403, {'message': 'Authorization required'}
async def render_html1(request):
"""Return any string to make an HTML response."""
return "<h1>I would be rendered as HTML</h1>"
async def render_html2(request):
"""Return a tuple to set HTTP status."""
return 201, 'Record Created'
# Starlette Responses works as well too
from starlette.responses import HTMLResponse
async def render_normal(request):
"""Starlette Responses are returned as is."""
return HTMLResponse('Common behaviour', status_code=200)
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/starlette-views/issues
Contributing
Development of the project happens at: https://github.com/klen/starlette-views
License
Licensed under a MIT license.
Metadata
Release files for starlette-views 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| starlette_views-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for starlette_views-0.0.4-py3-none-any.whl |
Release files / starlette_views-0.0.4-py3-none-any.whl
| Download URL | starlette_views-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8d3766c39f003434d648dc6335741118473c24a3dac4d20dac02c499071e3ea
|
|
BLAKE2b-256 checksum How to use checksums |
5c0479597adb38b019e23d2452705af1dcac05ef1082870c2a14d5437d18c09e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.0
|
Security for starlette-views 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.