Warning: Bocadillo is now UNMAINTAINED. Users are recommended to migrate to a supported alternative, such as Starlette or FastAPI. Please see #344 for more information.
bocadillo.plugins
use_providers
use_providers(app:'App')
Discover and configure providers.
Ensures that app-scoped providers are setup on app startup, and tore down on app shutdown.
Settings:
PROVIDER_MODULES
(list of str, optional): a list of Python modules (e.g.path.to.providersconf
) where Bocadillo should look for providers.
use_allowed_hosts
use_allowed_hosts(app:'App')
Restrict which hosts an application is allowed to be served at.
Settings:
ALLOWED_HOSTS
(list of str, optional): a list of hosts. If the list contains"*"
, any host is allowed. Defaults to["*"]
.
use_cors
use_cors(app:'App')
Enable CORS (Cross-Origin Resource Sharing) headers.
Settings:
CORS
(bool or dict): ifTrue
, the default configuration defined in constants.py is used. Otherwise, the dictionary is passed to Starlette's CORSMiddleware.
use_gzip
use_gzip(app:'App')
Enable GZip compression.
Settings:
GZIP
(bool): ifTrue
, automatically compress responses for clients that support it. Defaults toFalse
.GZIP_MIN_SIZE
(int): compress only responses that have more bytes than the specified value. Defaults to1024
.
use_hsts
use_hsts(app:'App')
Enable HSTS.
Settings:
HSTS
(bool): ifTrue
, HTTP traffic is automatically redirected to HTTPS. Defaults toFalse
.
use_sessions
use_sessions(app:'App')
Enable cookie-based signed sessions.
Settings:
SESSIONS
(bool or dict): ifTrue
, the secret key is obtained from theSECRET_KEY
environment variable. Otherwise, it must be a dictionary which will be passed to Starlette's SessionMiddleware.
use_staticfiles
use_staticfiles(app:'App')
Enable static files serving with WhiteNoise.
Settings:
STATIC_DIR
(str): the name of the directory containing static files, relative to the application entry point. Set toNone
to not serve any static files. Defaults to"static"
.STATIC_ROOT
(str): the path prefix for static assets. Defaults to"static"
.STATIC_CONFIG
(dict): extra static files configuration attributes. See also #::bocadillo.staticfiles#static.
use_typesystem_validation_error_handling
use_typesystem_validation_error_handling(app:'App')
Setup an error handler for typesystem.ValidationError
.
This plugin allows to validate TypeSystem schemas while letting the
framework deal with formatting and sending back a 400 Bad Request
error response in case of invalid data.
Settings:
HANDLE_TYPESYSTEM_VALIDATION_ERRORS
(bool): Set toFalse
to disable this plugin. Defaults toTrue
.