5. API Reference¶
5.1. tozti.utils
¶
-
exception
tozti.utils.
APIError
(msg=None, status=None, **kwargs)¶ Base class for API errors.
-
to_response
()¶ Create an aiohttp.web.Response signifiying the error.
-
-
class
tozti.utils.
ExtendedJSONEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ JSON encoder handling datetime.datetime and uuid.UUID.
-
class
tozti.utils.
RouteDef
(path, name=None)¶ Definition of a route.
The method
get()
,post()
,put()
, etc can be used as decorators to specify the handler for the given HTTP method.-
any
(handler)¶ Decorator used to specify handler for every method.
-
delete
(handler)¶ Decorator used to specify
DELETE
method handler.
-
get
(handler)¶ Decorator used to specify
GET
method handler.
-
head
(handler)¶ Decorator used to specify
HEAD
method handler.
-
options
(handler)¶ Decorator used to specify
OPTIONS
method handler.
-
patch
(handler)¶ Decorator used to specify
PATCH
method handler.
-
post
(handler)¶ Decorator used to specify
GET
method handler.
-
put
(handler)¶ Decorator used to specify
PUT
method handler.
-
register
(app)¶ Add all our routes to the given aiohttp.web.Application.
-
route
(*meth)¶ Decorator (with arguments) used to specify HTTP handler.
-
-
class
tozti.utils.
RouterDef
¶ Handle route definitions.
This object can be used as argument to
aiohttp.web.UrlDispatcher.add_routes()
.Sample usage:
router = RouterDef() route = router.add_route('/foo') @route.get def handle_get(req): return ...
See aiohttp for more informations on resources and routing.
-
add_prefix
(prefix)¶ Prefix every contained route.
-
add_route
(path, name=None)¶ Add and return a route with given path to the router.
-
-
tozti.utils.
json_response
(data, **kwargs)¶ Wrapper for aiohttp.web.json_response with extended JSON encoder.
-
tozti.utils.
validate
(inst, schema)¶ Validate data against a JsonSchema.
5.2. tozti.store
¶
-
tozti.store.
open_db
(app, types)¶ Initialize storage backend at app startup.
-
tozti.store.
close_db
(app)¶ Close storage backend at app cleanup.
5.3. tozti.app
¶
-
exception
tozti.app.
DependencyCycle
¶ Exception raised when a dependency cycle is detected in extensions.
-
class
tozti.app.
App
¶ The Tozti server.
-
main
(loop=None)¶ Start the server.
-
register
(extension)¶ Register an extension.
-
-
class
tozti.app.
Extension
(name, router=None, includes=(), static_dir=None, dependencies=(), _god_mode=None, on_response_prepare=None, on_startup=None, on_cleanup=None, on_shutdown=None, types={}, **kwargs)¶ A tozti extension
Represents a Tozti extension
-
name
¶ str – The name of the extension
-
includes
¶ list – A list of files included by the extension
-
static_dir
¶ str – Path of the static dir of the module
-
_god_mode
¶ function – god mode function
-
on_response_prepare
¶ function – A function to be executed when the hook on_response_prepare is executed by aiohttp
-
on_cleanup
¶ function – A function to be executed when the hook on_cleanup is executed by aiohttp
-
on_startup
¶ function – A function to be executed when the hook on_response_prepare is executed by aiohttp
-
on_shutdown
¶ function – A function to be executed when the hook on_shutdown is executed by aiohttp
-
check_sane
()¶ Check if the extension is sane. In other words, check if the every files it refers to exists
Raises: ValueError exception if one check failed.
-
set_static_dir_absolute
(absolute_prefix)¶ Set this extension static dir to be absolute. Check if this is feasible
Parameters: absolute_prefix – the absolute path that will lead to static_path after transformation
-