dazzler.system package¶
Dazzler systems (API)
Requirements are JS/CSS resources to include on rendering.
Packages hold components info and it’s requirements.
Component Aspects are shared between backend and frontend with bindings.
Generate components with
dazzler generate metadata.json output_dirPage holds meta data for rendering, requirements, routes, layout, bindings.
- class dazzler.system.Aspect(name=None, default=undefined, required=False, children=False, docstring=None)[source]¶
Bases:
objectAspects of component are represented on both backend and frontend.
- class dazzler.system.Binding(trigger, states=None, call=False)[source]¶
Bases:
objectBind a function to execute when the trigger aspect change.
- class dazzler.system.BindingContext(identity, request, trigger, states, websocket, request_queue, create_task)[source]¶
Bases:
dazzler.system._binding.BaseContextContext used by websockets binding,
@page.bind).Can request aspects from the frontend and interact with the
WebStorageapi.- async get_aspect(identity, aspect)[source]¶
Request the value of an aspect from the frontend.
- Parameters
identity (
str) – Component to get aspect from.aspect (
str) – Name of the aspect property.
- Returns
- class dazzler.system.BoundAspect(handler, trigger, states=None, call=False)[source]¶
Bases:
objectA trigger aspect bound to a method intended to be called when changed.
Data holder for the handler, trigger and state.
- prepare()[source]¶
Prepare the binding for serialization.
- Return type
list- Returns
list of dict with trigger and states definitions.
- property triggers¶
- class dazzler.system.CallContext(identity, request, trigger, states)[source]¶
Bases:
dazzler.system._binding.BaseContextContext of a call binding is used to set aspects on a request.
- class dazzler.system.Middleware[source]¶
Bases:
objectMiddleware functions are called before every routes registered by dazzler.
Add callback by returning a function taking the response as argument.
from dazzler.system import Middleware class MyMiddleware(Middleware): async def __call__(self, request): async def set_cookie(response): response.set_cookie('cookie', 'value') return set_cookie
- class dazzler.system.Package(name, components=None, requirements=None, routes=None)[source]¶
Bases:
object- package_registry = {'dazzler_auth': <Package "dazzler_auth">, 'dazzler_calendar': <Package "dazzler_calendar">, 'dazzler_core': <Package "dazzler_core">, 'dazzler_electron': <Package "dazzler_electron">, 'dazzler_extra': <Package "dazzler_extra">, 'dazzler_icons': <Package "dazzler_icons">, 'dazzler_markdown': <Package "dazzler_markdown">, 'dazzler_renderer': <Package "dazzler_renderer">}¶
- class dazzler.system.Page(name, layout, url=None, bindings=None, routes=None, requirements=None, requirements_dir='requirements', title=None, lang='en', header='', footer='', favicon='', meta_tags=None, packages=None, require_login=False, electron_window=None, authorizations=None)[source]¶
Bases:
objectA page of the application.
- __init__(name, layout, url=None, bindings=None, routes=None, requirements=None, requirements_dir='requirements', title=None, lang='en', header='', footer='', favicon='', meta_tags=None, packages=None, require_login=False, electron_window=None, authorizations=None)[source]¶
- Parameters
name (
str) – Unique name for the page, usually give __name__.layout (
Union[Component,Callable[[Request],Awaitable[Component]]]) – Root component or function returning a Component. In the case of a function, the request will be None on setup.url (
Optional[str]) – Url, default to/name.bindings (
Optional[list]) – Bindings of component aspects for this page.routes (
Optional[List[Route]]) – Additional routes to register with this page.requirements (
Optional[List[Requirement]]) – List of requirements totitle (
Optional[str]) – Title of the page.lang (
str) – lang attribute of the html tag.header (
str) – Static header to include as first child on the page.footer (
str) – Static footer to include as last child on the page.favicon (
str) – Url to favicon for the page.meta_tags (
Optional[List[Dict[str,str]]]) – Meta tags of the page.packages (
Optional[List[str]]) – Packages list to use on the page instead of the whole registry.require_login (
bool) – Page requires that user is logged in.electron_window (
Optional[ElectronWindowSettings]) – Settings for the electron window like size.authorizations (
Optional[list]) – Rules for authorization.
- bind(trigger, *states, once=False)[source]¶
Attach a function to be called when the trigger update on the client.
- get_binding(key)[source]¶
Get the binding from the trigger key.
- Parameters
key – Trigger key
- Return type
- Returns
- async prepare(request, debug=False, external=False)[source]¶
Prepare the page for rendering.
- Parameters
request (
Request) – The request to prepare for.debug – To collect dev package
external – Serve external requirements if available.
- Return type
dict- Returns
prepared dict with layout and page name.
- route(path, method=RouteMethod.GET, name=None, prefix=True)[source]¶
Add a route with a decorator.
- Parameters
path – Url to handle.
method (
Union[str,RouteMethod]) – Method of the route.name – Unique name for the route.
prefix – Prefix the path with the page path.
- Returns
- tie(trigger, *target, once=None)[source]¶
Update target(s) aspect on trigger from the frontend.
Example
from dazzler.system import Page from dazzler.components import core page = Page( __name__, core.Container([ core.Input(identity='input'), core.Container(identity='output') ]) ) page.tie('value@input', 'children@output')
- class dazzler.system.Requirement(internal=None, kind=None, name=None, package=None, dev=None, external=None, page=None, integrity=None)[source]¶
Bases:
objectRepresents a static asset to include as dependency for rendering.
- __init__(internal=None, kind=None, name=None, package=None, dev=None, external=None, page=None, integrity=None)[source]¶
- Parameters
internal (
Optional[str]) – Local path of the requirement to include on the page.kind (
Optional[str]) – The file extension.name (
Optional[str]) – The file name.package (
Optional[str]) – The package related to this requirement.dev (
Optional[bool]) – If the requirement is a dev requirement to serve only when in debug mode.external (
Optional[str]) – URL to serve instead when running withprefer_externalmode enable in the configs.page (
Optional[str]) – The page related to this requirement.integrity (
Optional[str]) – The integrity hash. (sri)
- class dazzler.system.RouteMethod(value)[source]¶
Bases:
precept._tools.AutoNameEnumAn enumeration.
- CONNECT = 'connect'¶
- DELETE = 'delete'¶
- GET = 'get'¶
- HEAD = 'head'¶
- OPTIONS = 'options'¶
- PATCH = 'patch'¶
- POST = 'post'¶
- PUT = 'put'¶
- class dazzler.system.State(identity, aspect, regex=False)[source]¶
Bases:
dazzler.system._binding._BindUsable aspect value in bound aspect without trigger on change.
- class dazzler.system.Target(shorthand=None, identity=None, aspect=None, regex=False)[source]¶
Bases:
dazzler.system._binding._BindA connection target that will be updated when the trigger is updated on the frontend.
Target has shorthand syntax
aspect@identityto use with transforms.- __init__(shorthand=None, identity=None, aspect=None, regex=False)[source]¶
- Parameters
identity (
Optional[str]) – The identity of the component to bind.aspect (
Optional[str]) – Aspect name to trigger/state.regex (
bool) – Identity and aspects are converted into regex and matched against for trigger and states.
- class dazzler.system.Trigger(identity, aspect, regex=False, once=None, skip_initial=False)[source]¶
Bases:
dazzler.system._binding._BindTrigger the bound aspect callbacks.
- dazzler.system.assets_to_requirements(path, data, dev_data=None, dev_path=None, package_name=None, external=None)[source]¶
Turns the output of webpack-assets-tracker into a list of Requirements
- Parameters
path (
str) – Path where production assets are locateddata (
dict) – Bundle tracker data.’dev_data (
Optional[dict]) – Bundle tracker dev data, if not provided take data.dev_path (
Optional[str]) – Path where dev assets are located.package_name (
Optional[str]) – The name of the package if used for packages.external (
Optional[str]) – External base path for the requirement.
- Return type
List[Requirement]- Returns
- dazzler.system.collect_requirements(directory, page=None)[source]¶
Collect all js/css files in the directory and map them as requirement
- Parameters
directory (
str) –page (
Optional[str]) –
- Returns
Submodules¶
dazzler.system.auth module¶
- class dazzler.system.auth.AuthBackend[source]¶
Bases:
objectHandle the request part of authentication protocols.
- async get_username(request)[source]¶
Get the username from the request.
- Parameters
request (
Request) – Incoming request.- Return type
str- Returns
Retrieved username.
- async is_authenticated(request)[source]¶
If the request is authenticated.
- Parameters
request (
Request) – The request to verify if authentication credentials are provided.- Return type
bool- Returns
Whether the user is authenticated.
- async login(user, request, response)[source]¶
Do what it takes to store the login info after being successfully authenticated by the authenticator.
- Parameters
user (
User) – The authenticated userrequest (
Request) – Incoming request.response (
Response) – A redirect response if needed to set cookies.
- Returns
- class dazzler.system.auth.AuthMiddleware(app, auth)[source]¶
Bases:
dazzler.system._middleware.MiddlewareAdd the user if authenticated to the request object.
- class dazzler.system.auth.AuthSessionBackend[source]¶
Bases:
dazzler.system.auth.AuthBackendAuth Backend integrated with the session system.
- async get_username(request)[source]¶
Get the username from the request.
- Parameters
request (
Request) – Incoming request.- Return type
str- Returns
Retrieved username.
- async is_authenticated(request)[source]¶
If the request is authenticated.
- Parameters
request (
Request) – The request to verify if authentication credentials are provided.- Return type
bool- Returns
Whether the user is authenticated.
- async login(user, request, response)[source]¶
Do what it takes to store the login info after being successfully authenticated by the authenticator.
- Parameters
user (
User) – The authenticated userrequest (
Request) – Incoming request.response (
Response) – A redirect response if needed to set cookies.
- Returns
- class dazzler.system.auth.Authenticator(app)[source]¶
Bases:
objectBase authenticator, a subclass of this must be presented to DazzlerAuth init in order to provide authentication for an app.
- app = None¶
- async authenticate(username, password)[source]¶
For login purpose.
- Parameters
username (
str) –password (
str) –
- Return type
Optional[User]- Returns
- class dazzler.system.auth.DazzlerAuth(app, authenticator, backend=None, login_page=None, default_redirect=None, register_page=None)[source]¶
Bases:
objectHandle the logic for page authentication.
Requires an authenticator to provide the end user authentication method.
Default to session backend, make sure a session middleware is present.
Activates in the configs with:
[authentication] enable = True authenticator = “module.submodule:AuthenticatorClass”
- __init__(app, authenticator, backend=None, login_page=None, default_redirect=None, register_page=None)[source]¶
- Parameters
app (dazzler.Dazzler) –
backend (
Optional[AuthBackend]) –
dazzler.system.session module¶
- class dazzler.system.session.FileSessionBackEnd(app)[source]¶
Bases:
dazzler.system.session.SessionBackEndSession backed by the file system.
Should only be used for development purpose where redis or another solution is not available.
- async delete(session_id, key)[source]¶
Delete a session key value.
- Parameters
session_id (
str) – Session to delete the key for.key (
str) – The key to delete.
- Returns
- class dazzler.system.session.Session(session_id, query_queue)[source]¶
Bases:
objectSession object available in requests by the middleware
Access with
request['session']. Or from binding:context.session- __init__(session_id, query_queue)[source]¶
- Parameters
session_id (
str) – The session id to perform operations.query_queue (
Queue) – To send commands up.
- class dazzler.system.session.SessionAction(value)[source]¶
Bases:
enum.EnumAn enumeration.
- DELETE = 3¶
- GET = 1¶
- SET = 2¶
- class dazzler.system.session.SessionBackEnd(app)[source]¶
Bases:
objectBase class to save & load sessions.
- async delete(session_id, key)[source]¶
Delete a session key value.
- Parameters
session_id (
str) – Session to delete the key for.key (
str) – The key to delete.
- Returns
- class dazzler.system.session.SessionMiddleware(app, backend=None)[source]¶
Bases:
dazzler.system._middleware.MiddlewareInsert session objects into requests.
- __init__(app, backend=None)[source]¶
- Parameters
app (dazzler.Dazzler) – Dazzler application.
backend (SessionBackEnd) –
dazzler.system.transforms module¶
Ties & transform API
- class dazzler.system.transforms.Add(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformPerform an addition on the chain value.
- class dazzler.system.transforms.Append(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformAppend a value a the end of the chained list.
- class dazzler.system.transforms.AspectValue(target)[source]¶
Bases:
dazzler.system.transforms._TargetTransformResolve the target value.
- class dazzler.system.transforms.Concat(other)[source]¶
Bases:
dazzler.system.transforms.TransformConcat a list or string into a new string/list containing entries from both sides.
- class dazzler.system.transforms.Divide(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformDivision operation Left / Right
- class dazzler.system.transforms.Filter(comparison)[source]¶
Bases:
dazzler.system.transforms._ComparableFilter elements of the list
- class dazzler.system.transforms.Find(comparison)[source]¶
Bases:
dazzler.system.transforms._ComparableFind an item in a list with a comparison.
from dazzler.system.transforms import RawValue, Find, Get, Equals RawValue([{'a': 'a', 'b': 'b'}, {'a': 'b', 'b': 'a'}]) .transform(Find(Get('a').t(Equals('b')))) # => {'a': 'b', 'b': 'a'}
- class dazzler.system.transforms.Format(template)[source]¶
Bases:
dazzler.system.transforms.TransformFormat the value into the template.
Template format:
${key}For primitive values (string, numbers), the value will be formatted in
${value}template key.Objects are formatted with their keys items formatted with the value.
from dazzler.system.transforms import RawValue, Format RawValue('foo').Format('${value} bar') # => 'foo bar' RawValue({'a': 'foo', 'b': 'bar'}).Format('${a} ${b}') # => 'foo bar' RawValue(['foo', 'bar']).Format('${0} ${1}') # => 'foo bar'
- class dazzler.system.transforms.FromJson[source]¶
Bases:
dazzler.system.transforms.TransformParse the chain value from JSON.
- class dazzler.system.transforms.FromPairs[source]¶
Bases:
dazzler.system.transforms.TransformTransform a list of list of key value pairs into an object.
- class dazzler.system.transforms.Get(field)[source]¶
Bases:
dazzler.system.transforms.TransformGet the field value of the chain object.
- class dazzler.system.transforms.Greater(other)[source]¶
Bases:
dazzler.system.transforms._Comparison
- class dazzler.system.transforms.GreaterOrEquals(other)[source]¶
Bases:
dazzler.system.transforms._Comparison
- class dazzler.system.transforms.If(comparison, then, otherwise=None)[source]¶
Bases:
dazzler.system.transforms._ComparableInitiate a comparison on the value.
thenis execute if the comparison isTrueelseotherwisewill be executed if defined.from dazzler.system.transforms import If, RawValue, Equals, Format RawValue('foo').t(If(Equals('foo'), then=Format('${value} bar')))
- class dazzler.system.transforms.Includes(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformTrue if value is included in the chained list.
- class dazzler.system.transforms.Insert(target, front=False)[source]¶
Bases:
dazzler.system.transforms._TargetTransformInsert the value into the target list.
- class dazzler.system.transforms.Length[source]¶
Bases:
dazzler.system.transforms.TransformResolve the length of the list.
- class dazzler.system.transforms.LesserOrEquals(other)[source]¶
Bases:
dazzler.system.transforms._Comparison
- class dazzler.system.transforms.Map(transform)[source]¶
Bases:
dazzler.system.transforms._TransformableMap a chained array values.
- class dazzler.system.transforms.Merge(other, direction='right', deep=False)[source]¶
Bases:
dazzler.system.transforms.TransformMerge a chained
dictvalue with anotherdict, either raw value or aTargetaspect.from dazzler.system.transforms import RawValue, Merge RawValue({'a': 1}).transform(Merge({'b': 2})) # => {'a': 1, 'b': 2}
- class dazzler.system.transforms.Modulus(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformPerform a modulus operation on the chain.
- class dazzler.system.transforms.Multiply(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformMultiply chain value * value
- class dazzler.system.transforms.NotEquals(other)[source]¶
Bases:
dazzler.system.transforms._Comparison
- class dazzler.system.transforms.Pick(fields)[source]¶
Bases:
dazzler.system.transforms.TransformPick the fields of the object.
from dazzler.system.transforms import RawValue, Pick RawValue({'a': 1, 'b': 2, 'c': 3}).t(Pick(['a', 'b'])) # => {'a': 1, 'b': 2}
- class dazzler.system.transforms.Pluck(field)[source]¶
Bases:
dazzler.system.transforms.TransformTake a value at
fieldfrom a list of objects.from dazzler.system.transforms import RawValue, Pluck RawValue([{'a': 1, 'b': 2, 'c': 3}]).t(Pick('a')) # => [1]
- class dazzler.system.transforms.Prepend(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformPrepend a value at the beginning of the list.
- class dazzler.system.transforms.Put(key, target)[source]¶
Bases:
dazzler.system.transforms.TransformPut the value at key on target
Target should be a dict or a ~.dazzler.system.Target aspect resolving to a dict.
- class dazzler.system.transforms.Range(start, end, step=1)[source]¶
Bases:
dazzler.system.transforms.TransformReturn an array of number from
starttoend
- class dazzler.system.transforms.RawValue(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformResolve a raw value.
- class dazzler.system.transforms.Reduce(transform)[source]¶
Bases:
dazzler.system.transforms._TransformableReduce the list value
- class dazzler.system.transforms.Reverse[source]¶
Bases:
dazzler.system.transforms.TransformReverse a string or array elements.
- class dazzler.system.transforms.Set(key, value)[source]¶
Bases:
dazzler.system.transforms.TransformSet the key value on the trigger value.
Value can be raw or a
dazzler.system.Targetaspect.
- class dazzler.system.transforms.Slice(start, stop)[source]¶
Bases:
dazzler.system.transforms.TransformTake a slice of a list from
starttostop.
- class dazzler.system.transforms.Sort(transform)[source]¶
Bases:
dazzler.system.transforms._TransformableSort transform should return a number
- class dazzler.system.transforms.Split(separator)[source]¶
Bases:
dazzler.system.transforms.TransformSplit a string value into a list.
- class dazzler.system.transforms.Sub(value)[source]¶
Bases:
dazzler.system.transforms._ValueTransformSubtract values.
- class dazzler.system.transforms.Take(n)[source]¶
Bases:
dazzler.system.transforms.TransformTake the first n elements of the list.
- class dazzler.system.transforms.TiedTransform(trigger, targets)[source]¶
Bases:
object- __init__(trigger, targets)[source]¶
- Parameters
trigger (dazzler.system.Trigger) – The aspect starting a tie chain on update.
targets (typing.List[dazzler.system.Target]) – Aspects to update.
- class dazzler.system.transforms.ToJson[source]¶
Bases:
dazzler.system.transforms.TransformSerialize the chain value to JSON.
- class dazzler.system.transforms.ToLower[source]¶
Bases:
dazzler.system.transforms.TransformTransform a string chained value to lower case.
- class dazzler.system.transforms.ToPairs[source]¶
Bases:
dazzler.system.transforms.TransformTransform an object into pairs of [key, value]
- class dazzler.system.transforms.ToUpper[source]¶
Bases:
dazzler.system.transforms.TransformTransform a string chained value to upper case.
- class dazzler.system.transforms.Transform[source]¶
Bases:
objectExecution order: Recursive Left to Right
- class dazzler.system.transforms.Trim[source]¶
Bases:
dazzler.system.transforms.TransformTrim whitespace around a chained string value.
- class dazzler.system.transforms.Unique[source]¶
Bases:
dazzler.system.transforms.TransformFilter duplicates out of the list.