API Star Contrib
Contrib packages to add on to API Star.
Free software: MIT license
Documentation: https://api-star-contrib.readthedocs.io.
Features
CSRF Token Hook
Local Session Store (For Development)
Timezone Support
Redis Session Store
TODO
DB Session Store
Usage
Local Session Store (For Development)
from apistar import App, Route, http
from apistar_contrib.sessions import Session, SessionComponent, SessionHook, LocalMemorySessionStore
def use_session(session: Session, params: http.QueryParams):
for key, value in params:
session[key] = value
return session.data
def clear_session(session: Session):
session.clear()
return session.data
routes = [
Route('/', 'GET', use_session),
Route('/clear', 'GET', clear_session),
]
app = App(
routes=routes,
components=[SessionComponent(LocalMemorySessionStore)],
event_hooks=[SessionHook]
)
Redis Session Store
from apistar import App, Route, http
from apistar_contrib.sessions import Session, SessionComponent, SessionHook, RedisSessionStore
def use_session(session: Session, params: http.QueryParams):
for key, value in params:
session[key] = value
return session.data
def clear_session(session: Session):
session.clear()
return session.data
routes = [
Route('/', 'GET', use_session),
Route('/clear', 'GET', clear_session),
]
app = App(
routes=routes,
components=[SessionComponent(RedisSessionStore, 'redis://localhost:6379/0')],
event_hooks=[SessionHook]
)
CSRF Token
import os
from apistar import App, Route, http
from apistar_contrib.csrf import EnforceCsrfHook, rotate_token
def show_form():
return app.render_template(
'form.html',
show_csrf=True,
)
def show_no_csrf_form():
return app.render_template(
'form.html',
show_csrf=False,
)
def handle_form(request: http.Request):
# You should rotate CSRF tokens after successful login/logout
rotate_token(request)
return app.render_template(
'form.html',
show_csrf=True,
success=True,
)
routes = [
Route('/', 'GET', show_form),
Route('/no_csrf', 'GET', show_no_csrf_form),
Route('/handle', 'POST', handle_form),
]
BASE_DIR = os.path.dirname(__file__)
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
app = App(
routes=routes,
event_hooks=[EnforceCsrfHook],
template_dir=TEMPLATE_DIR,
)
<!-- templates/form.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSRF Form</title>
</head>
<body>
<ul>
<li><a href="{{ reverse_url('show_form') }}">Form with CSRF</a></li>
<li><a href="{{ reverse_url('show_no_csrf_form') }}">Form without CSRF</a></li>
</ul>
{% if success %}<h1>Successful POST</h1>{% endif %}
<form action="{{ reverse_url('handle_form') }}" method="post">
{% if show_csrf %} {{ csrf_token() }} {% endif %}
<button type="submit">Submit form {% if show_csrf %}with{% else %}without{% endif %} CSRF</button>
</form>
</body>
</html>
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.0.6 (2018-06-08)
Added Redis Session Store to README and tests
0.0.5 (2018-05-19)
Added Redis Session Store
Created first tests
0.0.4 (2018-05-18)
Remove default components
0.0.3 (2018-05-18)
Refactor Session component
0.0.2 (2018-05-17)
Add CSRF token hook
0.0.1 (2018-05-15)
First release on PyPI.
Metadata
Release files for apistar-contrib 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apistar-contrib-0.0.6.tar.gz | 12.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apistar_contrib-0.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / apistar-contrib-0.0.6.tar.gz
| Download URL | apistar-contrib-0.0.6.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
757478c28b73d3be97225373db54306cb771bc3d6c36e2bc1348b2108cef3102
|
|
BLAKE2b-256 checksum How to use checksums |
201370de512f825ea5fbdebe2bca81bcb38eacc5ab2822e4054207fbd19f6dd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / apistar_contrib-0.0.6-py3-none-any.whl
| Download URL | apistar_contrib-0.0.6-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2cb8a551cbb2804367da686088f2d7945d0d5e82cba7e589e1a62fb30455541
|
|
BLAKE2b-256 checksum How to use checksums |
4c8dab1375f2fdeb3930483f0615dc8c2fe1571080c6a5f90fa8dd2813e61a09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for apistar-contrib 0.0.6
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.