Python API#

_console#

ast_utils#

class reactpy._console.ast_utils.ChangedNode(node: 'ast.AST', parents: 'Sequence[ast.AST]')[source]#

Bases: object

Parameters
Return type

None

class reactpy._console.ast_utils.ElementConstructorInfo(call: 'ast.Call', props: 'ast.Dict | ast.Call', parents: 'Sequence[ast.AST]')[source]#

Bases: object

Parameters
Return type

None

rewrite_camel_case_props#

rewrite_keys#

backend#

_common#

async reactpy.backend._common.serve_with_uvicorn(app, host, port, started)[source]#

Run a development server for an ASGI application

Parameters
  • app (ASGIApplication | Any) –

  • host (str) –

  • port (int) –

  • started (asyncio.Event | None) –

Return type

None

reactpy.backend._common.safe_client_build_dir_path(path)[source]#

Prevent path traversal out of CLIENT_BUILD_DIR

Parameters

path (str) –

Return type

pathlib.Path

reactpy.backend._common.safe_web_modules_dir_path(path)[source]#

Prevent path traversal out of reactpy.config.REACTPY_WEB_MODULES_DIR

Parameters

path (str) –

Return type

pathlib.Path

reactpy.backend._common.traversal_safe_path(root, *unsafe)[source]#

Raise a ValueError if the unsafe path resolves outside the root dir.

Parameters
  • root (str | Path) –

  • unsafe (str | Path) –

Return type

Path

class reactpy.backend._common.CommonOptions(head=({'tagName': 'title', 'children': ['ReactPy']}, {'tagName': 'link', 'attributes': {'rel': 'icon', 'href': '/_reactpy/assets/reactpy-logo.ico', 'type': 'image/x-icon'}}), url_prefix='', serve_index_route=True)[source]#

Bases: object

Options for ReactPy’s built-in backed server implementations

Parameters
Return type

None

head: Sequence[VdomDict] | VdomDict | str = ({'tagName': 'title', 'children': ['ReactPy']}, {'tagName': 'link', 'attributes': {'rel': 'icon', 'href': '/_reactpy/assets/reactpy-logo.ico', 'type': 'image/x-icon'}})#

Add elements to the <head> of the application.

For example, this can be used to customize the title of the page, link extra scripts, or load stylesheets.

url_prefix: str = ''#

The URL prefix where ReactPy resources will be served from

serve_index_route: bool = True#

Automatically generate and serve the index route (/)

default#

class reactpy.backend.default.Options(*args, **kwds)[source]#

Bases: object

Configuration options that can be provided to the backend. This definition should not be used/instantiated. It exists only for type hinting purposes.

Parameters
  • args (Any) –

  • kwds (Any) –

Return type

NoReturn

reactpy.backend.default.configure(app, component, options=None)[source]#

Configure the given app instance to display the given component

Parameters
  • app (Any) –

  • component (RootComponentConstructor) –

  • options (None) –

Return type

None

reactpy.backend.default.create_development_app()[source]#

Create an application instance for development purposes

Return type

Any

async reactpy.backend.default.serve_development_app(app, host, port, started=None)[source]#

Run an application using a development server

Parameters
Return type

None

fastapi#

reactpy.backend.fastapi.create_development_app()[source]#

Create a development FastAPI application instance.

Return type

fastapi.applications.FastAPI

flask#

class reactpy.backend.flask.Options(head=({'tagName': 'title', 'children': ['ReactPy']}, {'tagName': 'link', 'attributes': {'rel': 'icon', 'href': '/_reactpy/assets/reactpy-logo.ico', 'type': 'image/x-icon'}}), url_prefix='', serve_index_route=True, cors=False)[source]#

Bases: reactpy.backend._common.CommonOptions

Render server config for reactpy.backend.flask.configure()

Parameters
Return type

None

cors: bool | dict[str, Any] = False#

Enable or configure Cross Origin Resource Sharing (CORS)

For more information see docs for flask_cors.CORS

reactpy.backend.flask.configure(app, component, options=None)[source]#

Configure the necessary ReactPy routes on the given app.

Parameters
  • app (Flask) – An application instance

  • component (RootComponentConstructor) – A component constructor

  • options (Options | None) – Options for configuring server behavior

Return type

None

reactpy.backend.flask.create_development_app()[source]#

Create an application instance for development purposes

Return type

flask.app.Flask

async reactpy.backend.flask.serve_development_app(app, host, port, started=None)[source]#

Run a development server for FastAPI

Parameters
Return type

None

reactpy.backend.flask.use_websocket()[source]#

A handle to the current websocket

Return type

simple_websocket.ws.Server

reactpy.backend.flask.use_request()[source]#

Get the current Request

Return type

flask.wrappers.Request

reactpy.backend.flask.use_connection()[source]#

Get the current Connection

Return type

reactpy.backend.types.Connection[reactpy.backend.flask._FlaskCarrier]

hooks#

reactpy.backend.hooks.use_connection()[source]#

Get the current Connection.

Return type

reactpy.backend.types.Connection[Any]

reactpy.backend.hooks.use_scope()[source]#

Get the current Connection’s scope.

Return type

collections.abc.MutableMapping[str, Any]

reactpy.backend.hooks.use_location()[source]#

Get the current Connection’s location.

Return type

reactpy.backend.types.Location

sanic#

class reactpy.backend.sanic.Options(head=({'tagName': 'title', 'children': ['ReactPy']}, {'tagName': 'link', 'attributes': {'rel': 'icon', 'href': '/_reactpy/assets/reactpy-logo.ico', 'type': 'image/x-icon'}}), url_prefix='', serve_index_route=True, cors=False)[source]#

Bases: reactpy.backend._common.CommonOptions

Render server config for reactpy.backend.sanic.configure()

Parameters
Return type

None

cors: bool | dict[str, Any] = False#

Enable or configure Cross Origin Resource Sharing (CORS)

For more information see docs for sanic_cors.CORS

reactpy.backend.sanic.configure(app, component, options=None)[source]#

Configure an application instance to display the given component

Parameters
  • app (Sanic[Any, Any]) –

  • component (RootComponentConstructor) –

  • options (Options | None) –

Return type

None

reactpy.backend.sanic.create_development_app()[source]#

Return a Sanic app instance in test mode

Return type

Sanic[Any, Any]

async reactpy.backend.sanic.serve_development_app(app, host, port, started=None)[source]#

Run a development server for sanic

Parameters
  • app (Sanic[Any, Any]) –

  • host (str) –

  • port (int) –

  • started (asyncio.Event | None) –

Return type

None

reactpy.backend.sanic.use_request()[source]#

Get the current Request

Return type

request.Request[Any, Any]

reactpy.backend.sanic.use_websocket()[source]#

Get the current websocket

Return type

sanic.server.websockets.connection.WebSocketConnection

reactpy.backend.sanic.use_connection()[source]#

Get the current Connection

Return type

reactpy.backend.types.Connection[reactpy.backend.sanic._SanicCarrier]

starlette#

class reactpy.backend.starlette.Options(head=({'tagName': 'title', 'children': ['ReactPy']}, {'tagName': 'link', 'attributes': {'rel': 'icon', 'href': '/_reactpy/assets/reactpy-logo.ico', 'type': 'image/x-icon'}}), url_prefix='', serve_index_route=True, cors=False)[source]#

Bases: reactpy.backend._common.CommonOptions

Render server config for reactpy.backend.starlette.configure()

Parameters
Return type

None

cors: bool | dict[str, Any] = False#

Enable or configure Cross Origin Resource Sharing (CORS)

For more information see docs for starlette.middleware.cors.CORSMiddleware

reactpy.backend.starlette.configure(app, component, options=None)[source]#

Configure the necessary ReactPy routes on the given app.

Parameters
  • app (Starlette) – An application instance

  • component (RootComponentConstructor) – A component constructor

  • options (Options | None) – Options for configuring server behavior

Return type

None

reactpy.backend.starlette.create_development_app()[source]#

Return a Starlette app instance in debug mode

Return type

starlette.applications.Starlette

async reactpy.backend.starlette.serve_development_app(app, host, port, started=None)[source]#

Run a development server for starlette

Parameters
  • app (Starlette) –

  • host (str) –

  • port (int) –

  • started (asyncio.Event | None) –

Return type

None

reactpy.backend.starlette.use_websocket()[source]#

Get the current WebSocket object

Return type

starlette.websockets.WebSocket

tornado#

reactpy.backend.tornado.configure(app, component, options=None)[source]#

Configure the necessary ReactPy routes on the given app.

Parameters
  • app (Application) – An application instance

  • component (ComponentConstructor) – A component constructor

  • options (CommonOptions | None) – Options for configuring server behavior

Return type

None

reactpy.backend.tornado.use_request()[source]#

Get the current HTTPServerRequest

Return type

tornado.httputil.HTTPServerRequest

class reactpy.backend.tornado.IndexHandler(application, request, **kwargs)[source]#

Bases: tornado.web.RequestHandler

Parameters
Return type

None

class reactpy.backend.tornado.ModelStreamHandler(application, request, **kwargs)[source]#

Bases: tornado.websocket.WebSocketHandler

A web-socket handler that serves up a new model stream to each new client

Parameters
Return type

None

async open(path='', *args, **kwargs)[source]#

Invoked when a new WebSocket is opened.

The arguments to open are extracted from the tornado.web.URLSpec regular expression, just like the arguments to tornado.web.RequestHandler.get.

open may be a coroutine. on_message will not be called until open has returned.

Changed in version 5.1: open may be a coroutine.

Parameters
  • path (str) –

  • args (Any) –

  • kwargs (Any) –

Return type

None

async on_message(message)[source]#

Handle incoming messages on the WebSocket

This method must be overridden.

Changed in version 4.5: on_message can be a coroutine.

Parameters

message (str | bytes) –

Return type

None

on_close()[source]#

Invoked when the WebSocket is closed.

If the connection was closed cleanly and a status code or reason phrase was supplied, these values will be available as the attributes self.close_code and self.close_reason.

Changed in version 4.0: Added close_code and close_reason attributes.

Return type

None

types#

class reactpy.backend.types.BackendType(*args, **kwargs)[source]#

Bases: Protocol[reactpy.backend.types._App]

Common interface for built-in web server/framework integrations

Options: Callable[[...], Any]#

A constructor for options passed to BackendType.configure()

configure(app, component, options=None)[source]#

Configure the given app instance to display the given component

Parameters
  • app (_App) –

  • component (RootComponentConstructor) –

  • options (Any | None) –

Return type

None

create_development_app()[source]#

Create an application instance for development purposes

Return type

reactpy.backend.types._App

async serve_development_app(app, host, port, started=None)[source]#

Run an application using a development server

Parameters
Return type

None

class reactpy.backend.types.Connection(scope, location, carrier)[source]#

Bases: Generic[reactpy.backend.types._Carrier]

Represents a connection with a client

Parameters
Return type

None

scope: collections.abc.MutableMapping[str, Any]#

An ASGI scope or WSGI environment dictionary

location: reactpy.backend.types.Location#

The current location (URL)

carrier: reactpy.backend.types._Carrier#

How the connection is mediated. For example, a request or websocket.

This typically depends on the backend implementation.

class reactpy.backend.types.Location(pathname, search)[source]#

Bases: object

Represents the current location (URL)

Analogous to, but not necessarily identical to, the client-side document.location object.

Parameters
  • pathname (str) –

  • search (str) –

Return type

None

pathname: str#

the path of the URL for the location

search: str#

A search or query string - a β€˜?’ followed by the parameters of the URL.

If there are no search parameters this should be an empty string

utils#

reactpy.backend.utils.run(component, host='127.0.0.1', port=None, implementation=None)[source]#

Run a component with a development server

Parameters
  • component (RootComponentConstructor) –

  • host (str) –

  • port (int | None) –

  • implementation (BackendType[Any] | None) –

Return type

None

reactpy.backend.utils.find_available_port(host, port_min=8000, port_max=9000)[source]#

Get a port that’s available for the given host and port range

Parameters
  • host (str) –

  • port_min (int) –

  • port_max (int) –

Return type

int

reactpy.backend.utils.all_implementations()[source]#

Yield all available server implementations

Return type

collections.abc.Iterator[reactpy.backend.types.BackendType[Any]]

core#

_f_back#

_life_cycle_hook#

class reactpy.core._life_cycle_hook.EffectFunc(*args, **kwargs)[source]#

Bases: Protocol

reactpy.core._life_cycle_hook.current_hook()[source]#

Get the current LifeCycleHook

Return type

reactpy.core._life_cycle_hook.LifeCycleHook

class reactpy.core._life_cycle_hook.LifeCycleHook(schedule_render)[source]#

Bases: object

An object which manages the β€œlife cycle” of a layout component.

The β€œlife cycle” of a component is the set of events which occur from the time a component is first rendered until it is removed from the layout. The life cycle is ultimately driven by the layout itself, but components can β€œhook” into those events to perform actions. Components gain access to their own life cycle hook by calling current_hook(). They can then perform actions such as:

  1. Adding state via use_state()

  2. Adding effects via add_effect()

  3. Setting or getting context providers via LifeCycleHook.set_context_provider() and get_context_provider() respectively.

Components can request access to their own life cycle events and state through hooks while LayoutType objects drive drive the life cycle forward by triggering events and rendering view changes.

Example

If removed from the complexities of a layout, a very simplified full life cycle for a single component with no child components would look a bit like this:

from reactpy.core._life_cycle_hook import LifeCycleHook
from reactpy.core.hooks import current_hook

# this function will come from a layout implementation
schedule_render = lambda: ...

# --- start life cycle ---

hook = LifeCycleHook(schedule_render)

# --- start render cycle ---

component = ...
await hook.affect_component_will_render(component)
try:
    # render the component
    ...

    # the component may access the current hook
    assert current_hook() is hook

    # and save state or add effects
    current_hook().use_state(lambda: ...)

    async def my_effect(stop_event):
        ...

    current_hook().add_effect(my_effect)
finally:
    await hook.affect_component_did_render()

# This should only be called after the full set of changes associated with a
# given render have been completed.
await hook.affect_layout_did_render()

# Typically an event occurs and a new render is scheduled, thus beginning
# the render cycle anew.
hook.schedule_render()


# --- end render cycle ---

hook.affect_component_will_unmount()
del hook

# --- end render cycle ---
Parameters

schedule_render (Callable[[], None]) –

Return type

None

use_state(function)[source]#

Add state to this hook

If this hook has not yet rendered, the state is appended to the state tuple. Otherwise, the state is retrieved from the tuple. This allows state to be preserved across renders.

Parameters

function (Callable[[], reactpy.core._life_cycle_hook.T]) –

Return type

reactpy.core._life_cycle_hook.T

add_effect(effect_func)[source]#

Add an effect to this hook

A task to run the effect is created when the component is done rendering. When the component will be unmounted, the event passed to the effect is triggered and the task is awaited. The effect should eventually halt after the event is triggered.

Parameters

effect_func (reactpy.core._life_cycle_hook.EffectFunc) –

Return type

None

set_context_provider(provider)[source]#

Set a context provider for this hook

The context provider will be used to provide state to any child components of this hook’s component which request a context provider of the same type.

Parameters

provider (reactpy.core.types.ContextProviderType[Any]) –

Return type

None

get_context_provider(context)[source]#

Get a context provider for this hook of the given type

The context provider will have been set by a parent component. If no provider is found, None is returned.

Parameters

context (Context[T]) –

Return type

ContextProviderType[T] | None

async affect_component_will_render(component)[source]#

The component is about to render

Parameters

component (reactpy.core.types.ComponentType) –

Return type

None

async affect_component_did_render()[source]#

The component completed a render

Return type

None

async affect_layout_did_render()[source]#

The layout completed a render

Return type

None

async affect_component_will_unmount()[source]#

The component is about to be removed from the layout

Return type

None

set_current()[source]#

Set this hook as the active hook in this thread

This method is called by a layout before entering the render method of this hook’s associated component.

Return type

None

unset_current()[source]#

Unset this hook as the active hook in this thread

Return type

None

_thread_local#

class reactpy.core._thread_local.ThreadLocal(default)[source]#

Bases: Generic[reactpy.core._thread_local._StateType]

Utility for managing per-thread state information

Parameters

default (Callable[[], reactpy.core._thread_local._StateType]) –

component#

reactpy.core.component.component(function)[source]#

A decorator for defining a new component.

Parameters

function (Callable[..., ComponentType | VdomDict | str | None]) – The component’s reactpy.core.proto.ComponentType.render() function.

Return type

Callable[…, Component]

class reactpy.core.component.Component(function, key, args, kwargs, sig)[source]#

Bases: object

An object for rending component models.

Parameters
Return type

None

events#

reactpy.core.events.event(function: Callable[[...], Any], *, stop_propagation: bool = False, prevent_default: bool = False) β†’ reactpy.core.events.EventHandler[source]#
reactpy.core.events.event(function: Literal[None] = None, *, stop_propagation: bool = False, prevent_default: bool = False) β†’ Callable[[Callable[[...], Any]], reactpy.core.events.EventHandler]

A decorator for constructing an EventHandler.

While you’re always free to add callbacks by assigning them to an element’s attributes

element = reactpy.html.button({"onClick": my_callback})

You may want the ability to prevent the default action associated with the event from taking place, or stopping the event from propagating up the DOM. This decorator allows you to add that functionality to your callbacks.

@event(stop_propagation=True, prevent_default=True)
def my_callback(*data):
    ...

element = reactpy.html.button({"onClick": my_callback})
Parameters
  • function – A function or coroutine responsible for handling the event.

  • stop_propagation – Block the event from propagating further up the DOM.

  • prevent_default – Stops the default actional associate with the event from taking place.

class reactpy.core.events.EventHandler(function, stop_propagation=False, prevent_default=False, target=None)[source]#

Bases: object

Turn a function or coroutine into an event handler

Parameters
  • function (EventHandlerFunc) – The function or coroutine which handles the event.

  • stop_propagation (bool) – Block the event from propagating further up the DOM.

  • prevent_default (bool) – Stops the default action associate with the event from taking place.

  • target (str | None) – A unique identifier for this event handler (auto-generated by default)

Return type

None

reactpy.core.events.to_event_handler_function(function, positional_args=True)[source]#

Make a EventHandlerFunc from a function or coroutine

Parameters
  • function (Callable[[...], Any]) – A function or coroutine accepting a number of positional arguments.

  • positional_args (bool) – Whether to pass the event parameters a positional args or as a list.

Return type

reactpy.core.types.EventHandlerFunc

reactpy.core.events.merge_event_handlers(event_handlers)[source]#

Merge multiple event handlers into one

Raises a ValueError if any handlers have conflicting stop_propagation or prevent_default attributes.

Parameters

event_handlers (collections.abc.Sequence[reactpy.core.types.EventHandlerType]) –

Return type

reactpy.core.types.EventHandlerType

reactpy.core.events.merge_event_handler_funcs(functions)[source]#

Make one event handler function from many

Parameters

functions (collections.abc.Sequence[reactpy.core.types.EventHandlerFunc]) –

Return type

reactpy.core.types.EventHandlerFunc

hooks#

reactpy.core.hooks.use_state(initial_value: Callable[[], reactpy.core.hooks._Type]) β†’ reactpy.core.types.State[reactpy.core.hooks._Type][source]#
reactpy.core.hooks.use_state(initial_value: reactpy.core.hooks._Type) β†’ reactpy.core.types.State[reactpy.core.hooks._Type]

See the full Use State docs for details

Parameters

initial_value – Defines the initial value of the state. A callable (accepting no arguments) can be used as a constructor function to avoid re-creating the initial value on each render.

Returns

A tuple containing the current state and a function to update it.

reactpy.core.hooks.use_effect(function: None = None, dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ Callable[[_EffectApplyFunc], None][source]#
reactpy.core.hooks.use_effect(function: _EffectApplyFunc, dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ None

See the full Use Effect docs for details

Parameters
  • function – Applies the effect and can return a clean-up function

  • dependencies – Dependencies for the effect. The effect will only trigger if the identity of any value in the given sequence changes (i.e. their id() is different). By default these are inferred based on local variables that are referenced by the given function.

Returns

If not function is provided, a decorator. Otherwise None.

reactpy.core.hooks.use_debug_value(message, dependencies=Ellipsis)[source]#

Log debug information when the given message changes.

Note

This hook only logs if REACTPY_DEBUG_MODE is active.

Unlike other hooks, a message is considered to have changed if the old and new values are !=. Because this comparison is performed on every render of the component, it may be worth considering the performance cost in some situations.

Parameters
  • message (Any | Callable[[], Any]) – The value to log or a memoized function for generating the value.

  • dependencies (Sequence[Any] | ellipsis | None) – Dependencies for the memoized function. The message will only be recomputed if the identity of any value in the given sequence changes (i.e. their id() is different). By default these are inferred based on local variables that are referenced by the given function.

Return type

None

reactpy.core.hooks.create_context(default_value)[source]#

Return a new context type for use in use_context()

Parameters

default_value (reactpy.core.hooks._Type) –

Return type

reactpy.core.types.Context[reactpy.core.hooks._Type]

reactpy.core.hooks.use_context(context)[source]#

Get the current value for the given context type.

See the full Use Context docs for more information.

Parameters

context (reactpy.core.types.Context[reactpy.core.hooks._Type]) –

Return type

reactpy.core.hooks._Type

reactpy.core.hooks.use_connection()[source]#

Get the current Connection.

Return type

reactpy.backend.types.Connection[Any]

reactpy.core.hooks.use_scope()[source]#

Get the current Connection’s scope.

Return type

collections.abc.MutableMapping[str, Any]

reactpy.core.hooks.use_location()[source]#

Get the current Connection’s location.

Return type

reactpy.backend.types.Location

reactpy.core.hooks.use_reducer(reducer, initial_value)[source]#

See the full Use Reducer docs for details

Parameters
  • reducer (Callable[[reactpy.core.hooks._Type, reactpy.core.hooks._ActionType], reactpy.core.hooks._Type]) – A function which applies an action to the current state in order to produce the next state.

  • initial_value (reactpy.core.hooks._Type) – The initial state value (same as for use_state())

Returns

A tuple containing the current state and a function to change it with an action

Return type

tuple[~_Type, Callable[[~_ActionType], NoneType]]

reactpy.core.hooks.use_callback(function: None = None, dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ Callable[[reactpy.core.hooks._CallbackFunc], reactpy.core.hooks._CallbackFunc][source]#
reactpy.core.hooks.use_callback(function: reactpy.core.hooks._CallbackFunc, dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ reactpy.core.hooks._CallbackFunc

See the full Use Callback docs for details

Parameters
  • function – The function whose identity will be preserved

  • dependencies – Dependencies of the callback. The identity the function will be updated if the identity of any value in the given sequence changes (i.e. their id() is different). By default these are inferred based on local variables that are referenced by the given function.

Returns

The current function

reactpy.core.hooks.use_memo(function: None = None, dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ reactpy.core.hooks._LambdaCaller[source]#
reactpy.core.hooks.use_memo(function: Callable[[], reactpy.core.hooks._Type], dependencies: Sequence[Any] | ellipsis | None = Ellipsis) β†’ reactpy.core.hooks._Type

See the full Use Memo docs for details

Parameters
  • function – The function to be memoized.

  • dependencies – Dependencies for the memoized function. The memo will only be recomputed if the identity of any value in the given sequence changes (i.e. their id() is different). By default these are inferred based on local variables that are referenced by the given function.

Returns

The current state

reactpy.core.hooks.use_ref(initial_value)[source]#

See the full Use State docs for details

Parameters

initial_value (reactpy.core.hooks._Type) – The value initially assigned to the reference.

Returns

A Ref object.

Return type

reactpy.utils.Ref[reactpy.core.hooks._Type]

reactpy.core.hooks.strictly_equal(x, y)[source]#

Check if two values are identical or, for a limited set or types, equal.

Only the following types are checked for equality rather than identity:

  • int

  • float

  • complex

  • str

  • bytes

  • bytearray

  • memoryview

Parameters
  • x (Any) –

  • y (Any) –

Return type

bool

layout#

class reactpy.core.layout.Layout(root)[source]#

Bases: object

Responsible for β€œrendering” components. That is, turning them into VDOM.

Parameters

root (ComponentType) –

Return type

None

async deliver(event)[source]#

Dispatch an event to the targeted handler

Parameters

event (reactpy.core.types.LayoutEventMessage) –

Return type

None

serve#

reactpy.core.serve.SendCoroutine#

Send model patches given by a dispatcher

alias of Callable[[reactpy.core.types.LayoutUpdateMessage], collections.abc.Awaitable[None]]

reactpy.core.serve.RecvCoroutine#

Called by a dispatcher to return a reactpy.core.layout.LayoutEventMessage

The event will then trigger an reactpy.core.proto.EventHandlerType in a layout.

alias of Callable[[], collections.abc.Awaitable[reactpy.core.types.LayoutEventMessage]]

exception reactpy.core.serve.Stop[source]#

Bases: BaseException

Deprecated

Stop serving changes and events

Raising this error will tell dispatchers to gracefully exit. Typically this is called by code running inside a layout to tell it to stop rendering.

async reactpy.core.serve.serve_layout(layout, send, recv)[source]#

Run a dispatch loop for a single view instance

Parameters
Return type

None

types#

class reactpy.core.types.State(value, set_value)[source]#

Bases: tuple

value: _Type#

Alias for field number 0

set_value: Callable[[_Type | Callable[[_Type], _Type]], None]#

Alias for field number 1

reactpy.core.types.ComponentConstructor#

Simple function returning a new component

alias of Callable[[…], ComponentType]

reactpy.core.types.RootComponentConstructor#

The root component should be constructed by a function accepting no arguments.

alias of Callable[[], ComponentType]

class reactpy.core.types.ComponentType(*args, **kwargs)[source]#

Bases: Protocol

The expected interface for all component-like objects

key: Key | None#

An identifier which is unique amongst a component’s immediate siblings

type: Any#

The function or class defining the behavior of this component

This is used to see if two component instances share the same definition.

render()[source]#

Render the component’s view model.

Return type

VdomDict | ComponentType | str | None

class reactpy.core.types.LayoutType(*args, **kwargs)[source]#

Bases: Protocol[reactpy.core.types._Render_co, reactpy.core.types._Event_contra]

Renders and delivers, updates to views and events to handlers, respectively

async render()[source]#

Render an update to a view

Return type

reactpy.core.types._Render_co

async deliver(event)[source]#

Relay an event to its respective handler

Parameters

event (reactpy.core.types._Event_contra) –

Return type

None

reactpy.core.types.VdomAttributes#

Describes the attributes of a VdomDict

reactpy.core.types.VdomChild: TypeAlias = 'ComponentType | VdomDict | str | None | Any'#

A single child element of a VdomDict

reactpy.core.types.VdomChildren: TypeAlias = 'Sequence[VdomChild] | VdomChild'#

Describes a series of VdomChild elements

class reactpy.core.types.VdomDict(_typename, _fields=None, /, **kwargs)[source]#

Bases: reactpy.core.types._VdomDictRequired, reactpy.core.types._VdomDictOptional

A VDOM dictionary

class reactpy.core.types.ImportSourceDict(_typename, _fields=None, /, **kwargs)[source]#

Bases: typing_extensions.TypedDict

class reactpy.core.types.VdomJson(_typename, _fields=None, /, **kwargs)[source]#

Bases: reactpy.core.types._RequiredVdomJson, reactpy.core.types._OptionalVdomJson

A JSON serializable form of VdomDict matching the VDOM_JSON_SCHEMA

reactpy.core.types.EventHandlerMapping#

A generic mapping between event names to their handlers

reactpy.core.types.EventHandlerDict: TypeAlias = 'dict[str, EventHandlerType]'#

A dict mapping between event names to their handlers

class reactpy.core.types.EventHandlerFunc(*args, **kwargs)[source]#

Bases: Protocol

A coroutine which can handle event data

class reactpy.core.types.EventHandlerType(*args, **kwargs)[source]#

Bases: Protocol

Defines a handler for some event

prevent_default: bool#

Whether to block the event from propagating further up the DOM

stop_propagation: bool#

Stops the default action associate with the event from taking place.

function: EventHandlerFunc#

A coroutine which can respond to an event and its data

target: str | None#

Typically left as None except when a static target is useful.

When testing, it may be useful to specify a static target ID so events can be triggered programmatically.

Note

When None, it is left to a LayoutType to auto generate a unique ID.

class reactpy.core.types.VdomDictConstructor(*args, **kwargs)[source]#

Bases: Protocol

Standard function for constructing a VdomDict

class reactpy.core.types.LayoutUpdateMessage(_typename, _fields=None, /, **kwargs)[source]#

Bases: typing_extensions.TypedDict

A message describing an update to a layout

type: Literal['layout-update']#

The type of message

path: str#

JSON Pointer path to the model element being updated

model: reactpy.core.types.VdomJson#

The model to assign at the given JSON Pointer path

class reactpy.core.types.LayoutEventMessage(_typename, _fields=None, /, **kwargs)[source]#

Bases: typing_extensions.TypedDict

Message describing an event originating from an element in the layout

type: Literal['layout-event']#

The type of message

target: str#

The ID of the event handler.

data: collections.abc.Sequence[Any]#

A list of event data passed to the event handler.

class reactpy.core.types.Context(*args, **kwargs)[source]#

Bases: Protocol[reactpy.core.types._Type]

Returns a ContextProvider component

class reactpy.core.types.ContextProviderType(*args, **kwargs)[source]#

Bases: reactpy.core.types.ComponentType, Protocol[reactpy.core.types._Type]

A component which provides a context value to its children

type: Context[_Type]#

The context type

property value: reactpy.core.types._Type#

Current context value

vdom#

reactpy.core.vdom.VDOM_JSON_SCHEMA = {'$ref': '#/definitions/element', '$schema': 'http://json-schema.org/draft-07/schema', 'definitions': {'element': {'dependentSchemas': {'error': {'properties': {'tagName': {'maxLength': 0}}}}, 'properties': {'attributes': {'type': 'object'}, 'children': {'$ref': '#/definitions/elementChildren'}, 'error': {'type': 'string'}, 'eventHandlers': {'$ref': '#/definitions/elementEventHandlers'}, 'importSource': {'$ref': '#/definitions/importSource'}, 'key': {'type': ['string', 'number', 'null']}, 'tagName': {'type': 'string'}}, 'required': ['tagName'], 'type': 'object'}, 'elementChildren': {'items': {'$ref': '#/definitions/elementOrString'}, 'type': 'array'}, 'elementEventHandlers': {'patternProperties': {'.*': {'$ref': '#/definitions/eventHandler'}}, 'type': 'object'}, 'elementOrString': {'if': {'type': 'object'}, 'then': {'$ref': '#/definitions/element'}, 'type': ['object', 'string']}, 'eventHandler': {'properties': {'preventDefault': {'type': 'boolean'}, 'stopPropagation': {'type': 'boolean'}, 'target': {'type': 'string'}}, 'required': ['target'], 'type': 'object'}, 'importSource': {'properties': {'fallback': {'if': {'not': {'type': 'null'}}, 'then': {'$ref': '#/definitions/elementOrString'}, 'type': ['object', 'string', 'null']}, 'source': {'type': 'string'}, 'sourceType': {'enum': ['URL', 'NAME']}, 'unmountBeforeUpdate': {'type': 'boolean'}}, 'required': ['source'], 'type': 'object'}}}#

JSON Schema describing serialized VDOM - see VDOM for more info

reactpy.core.vdom.validate_vdom_json(value)[source]#

Validate serialized VDOM - see VDOM_JSON_SCHEMA for more info

Parameters

value (Any) –

Return type

reactpy.core.types.VdomJson

reactpy.core.vdom.is_vdom(value)[source]#

Return whether a value is a VdomDict

This employs a very simple heuristic - something is VDOM if:

  1. It is a dict instance

  2. It contains the key "tagName"

  3. The value of the key "tagName" is a string

Note

Performing an isinstance(value, VdomDict) check is too restrictive since the user would be forced to import VdomDict every time they needed to declare a VDOM element. Giving the user more flexibility, at the cost of this check’s accuracy, is worth it.

Parameters

value (Any) –

Return type

bool

reactpy.core.vdom.vdom(tag: str, *children: VdomChildren) β†’ reactpy.core.types.VdomDict[source]#
reactpy.core.vdom.vdom(tag: str, attributes: collections.abc.Mapping[str, Any], *children: VdomChildren) β†’ reactpy.core.types.VdomDict

A helper function for creating VDOM elements.

Parameters
  • tag – The type of element (e.g. β€˜div’, β€˜h1’, β€˜img’)

  • attributes_and_children – An optional attribute mapping followed by any number of children or iterables of children. The attribute mapping must precede the children, or children which will be merged into their respective parts of the model.

  • key – A string indicating the identity of a particular element. This is significant to preserve event handlers across updates - without a key, a re-render would cause these handlers to be deleted, but with a key, they would be redirected to any newly defined handlers.

  • event_handlers – Maps event types to coroutines that are responsible for handling those events.

  • import_source – (subject to change) specifies javascript that, when evaluated returns a React component.

reactpy.core.vdom.make_vdom_constructor(tag, allow_children=True, import_source=None)[source]#

Return a constructor for VDOM dictionaries with the given tag name.

The resulting callable will have the same interface as vdom() but without its first tag argument.

Parameters
Return type

VdomDictConstructor

reactpy.core.vdom.custom_vdom_constructor(func)[source]#

Cast function to VdomDictConstructor

Parameters

func (reactpy.core.vdom._CustomVdomDictConstructor) –

Return type

reactpy.core.types.VdomDictConstructor

testing#

backend#

class reactpy.testing.backend.BackendFixture(host='127.0.0.1', port=None, app=None, implementation=None, options=None, timeout=None)[source]#

Bases: object

A test fixture for running a server and imperatively displaying views

This fixture is typically used alongside async web drivers like playwight.

Example

async with BackendFixture() as server:
    server.mount(MyComponent)
Parameters
  • host (str) –

  • port (int | None) –

  • app (Any | None) –

  • implementation (BackendType[Any] | None) –

  • options (Any | None) –

  • timeout (float | None) –

Return type

None

property log_records: list[logging.LogRecord]#

A list of captured log records

url(path='', query=None)[source]#

Return a URL string pointing to the host and point of the server

Parameters
  • path (str) – the path to a resource on the server

  • query (Any | None) – a dictionary or list of query parameters

Return type

str

list_logged_exceptions(pattern='', types=<class 'Exception'>, log_level=40, del_log_records=True)[source]#

Return a list of logged exception matching the given criteria

Parameters
  • log_level (int) – The level of log to check

  • exclude_exc_types – Any exception types to ignore

  • del_log_records (bool) – Whether to delete the log records for yielded exceptions

  • pattern (str) –

  • types (type[Any] | tuple[type[Any], ...]) –

Return type

list[BaseException]

common#

reactpy.testing.common.clear_reactpy_web_modules_dir()[source]#

Clear the directory where ReactPy stores registered web modules

Return type

None

class reactpy.testing.common.poll(function, *args, **kwargs)[source]#

Bases: Generic[reactpy.testing.common._R]

Wait until the result of an sync or async function meets some condition

Parameters
  • function (Callable[_P, Awaitable[_R] | _R]) –

  • args (_P.args) –

  • kwargs (_P.kwargs) –

Return type

None

async until(condition, timeout=5.0, delay=0.1, description='condition to be true')[source]#

Check that the coroutines result meets a condition within the timeout

Parameters
  • condition (Callable[[reactpy.testing.common._R], bool]) –

  • timeout (float) –

  • delay (float) –

  • description (str) –

Return type

None

async until_is(right, timeout=5.0, delay=0.1)[source]#

Wait until the result is identical to the given value

Parameters
  • right (reactpy.testing.common._R) –

  • timeout (float) –

  • delay (float) –

Return type

None

async until_equals(right, timeout=5.0, delay=0.1)[source]#

Wait until the result is equal to the given value

Parameters
  • right (reactpy.testing.common._R) –

  • timeout (float) –

  • delay (float) –

Return type

None

class reactpy.testing.common.HookCatcher(index_by_kwarg=None)[source]#

Bases: object

Utility for capturing a LifeCycleHook from a component

Example

hooks = HookCatcher(index_by_kwarg="thing")

@reactpy.component
@hooks.capture
def MyComponent(thing):
    ...

...  # render the component

# grab the last render of where MyComponent(thing='something')
hooks.index["something"]
# or grab the hook from the component's last render
hooks.latest

After the first render of MyComponent the HookCatcher will have captured the component’s LifeCycleHook.

Parameters

index_by_kwarg (str | None) –

capture(render_function)[source]#

Decorator for capturing a LifeCycleHook on each render of a component

Parameters

render_function (Callable[[...], Any]) –

Return type

Callable[[…], Any]

class reactpy.testing.common.StaticEventHandler[source]#

Bases: object

Utility for capturing the target of one event handler

Example

static_handler = StaticEventHandler()

@reactpy.component
def MyComponent():
    state, set_state = reactpy.hooks.use_state(0)
    handler = static_handler.use(lambda event: set_state(state + 1))
    return reactpy.html.button({"onClick": handler}, "Click me!")

# gives the target ID for onClick where from the last render of MyComponent
static_handlers.target

If you need to capture event handlers from different instances of a component the you should create multiple StaticEventHandler instances.

static_handlers_by_key = {
    "first": StaticEventHandler(),
    "second": StaticEventHandler(),
}

@reactpy.component
def Parent():
    return reactpy.html.div(Child(key="first"), Child(key="second"))

@reactpy.component
def Child(key):
    state, set_state = reactpy.hooks.use_state(0)
    handler = static_handlers_by_key[key].use(lambda event: set_state(state + 1))
    return reactpy.html.button({"onClick": handler}, "Click me!")

# grab the individual targets for each instance above
first_target = static_handlers_by_key["first"].target
second_target = static_handlers_by_key["second"].target
Return type

None

display#

class reactpy.testing.display.DisplayFixture(backend=None, driver=None, url_prefix='')[source]#

Bases: object

A fixture for running web-based tests using playwright

Parameters
  • backend (BackendFixture | None) –

  • driver (Browser | BrowserContext | Page | None) –

  • url_prefix (str) –

Return type

None

logs#

exception reactpy.testing.logs.LogAssertionError[source]#

Bases: AssertionError

An assertion error raised in relation to log messages.

reactpy.testing.logs.assert_reactpy_did_log(match_message='', error_type=None, match_error='')[source]#

Assert that ReactPy produced a log matching the described message or error.

Parameters
  • match_message (str) – Must match a logged message.

  • error_type (type[Exception] | None) – Checks the type of logged exceptions.

  • match_error (str) – Must match an error message.

Return type

Iterator[None]

reactpy.testing.logs.assert_reactpy_did_not_log(match_message='', error_type=None, match_error='')[source]#

Assert the inverse of assert_reactpy_logged()

Parameters
  • match_message (str) –

  • error_type (type[Exception] | None) –

  • match_error (str) –

Return type

Iterator[None]

reactpy.testing.logs.list_logged_exceptions(log_records, pattern='', types=<class 'Exception'>, log_level=40, del_log_records=True)[source]#

Return a list of logged exception matching the given criteria

Parameters
  • log_level (int) – The level of log to check

  • exclude_exc_types – Any exception types to ignore

  • del_log_records (bool) – Whether to delete the log records for yielded exceptions

  • log_records (list[logging.LogRecord]) –

  • pattern (str) –

  • types (type[Any] | tuple[type[Any], ...]) –

Return type

list[BaseException]

reactpy.testing.logs.capture_reactpy_logs()[source]#

Capture logs from ReactPy

Any logs produced in this context are cleared afterwards

Return type

collections.abc.Iterator[list[logging.LogRecord]]

web#

module#

reactpy.web.module.NAME_SOURCE = 'NAME'#

A named source - usually a Javascript package name

reactpy.web.module.URL_SOURCE = 'URL'#

A source loaded from a URL, usually a CDN

reactpy.web.module.module_from_url(url, fallback=None, resolve_exports=None, resolve_exports_depth=5, unmount_before_update=False)[source]#

Load a WebModule from a URL_SOURCE

Parameters
  • url (str) – Where the javascript module will be loaded from which conforms to the interface for Custom Javascript Components

  • fallback (Any | None) – What to temporarily display while the module is being loaded.

  • resolve_imports – Whether to try and find all the named exports of this module.

  • resolve_exports_depth (int) – How deeply to search for those exports.

  • unmount_before_update (bool) – Cause the component to be unmounted before each update. This option should only be used if the imported package fails to re-render when props change. Using this option has negative performance consequences since all DOM elements must be changed on each render. See #461 for more info.

  • resolve_exports (bool | None) –

Return type

WebModule

reactpy.web.module.module_from_template(template, package, cdn='https://esm.sh', fallback=None, resolve_exports=None, resolve_exports_depth=5, unmount_before_update=False)[source]#

Create a WebModule from a framework template

This is useful for experimenting with component libraries that do not already support ReactPy’s Custom Javascript Components interface.

Warning

This approach is not recommended for use in a production setting because the framework templates may use unpinned dependencies that could change without warning. It’s best to author a module adhering to the Custom Javascript Components interface instead.

Templates

  • react: for modules exporting React components

Parameters
  • template (str) – The name of the framework template to use with the given package.

  • package (str) – The name of a package to load. May include a file extension (defaults to .js if not given)

  • cdn (str) – Where the package should be loaded from. The CDN must distribute ESM modules

  • fallback (Any | None) – What to temporarily display while the module is being loaded.

  • resolve_imports – Whether to try and find all the named exports of this module.

  • resolve_exports_depth (int) – How deeply to search for those exports.

  • unmount_before_update (bool) – Cause the component to be unmounted before each update. This option should only be used if the imported package fails to re-render when props change. Using this option has negative performance consequences since all DOM elements must be changed on each render. See #461 for more info.

  • resolve_exports (bool | None) –

Return type

WebModule

reactpy.web.module.module_from_file(name, file, fallback=None, resolve_exports=None, resolve_exports_depth=5, unmount_before_update=False, symlink=False)[source]#

Load a WebModule from a given file

Parameters
  • name (str) – The name of the package

  • file (str | Path) – The file from which the content of the web module will be created.

  • fallback (Any | None) – What to temporarily display while the module is being loaded.

  • resolve_imports – Whether to try and find all the named exports of this module.

  • resolve_exports_depth (int) – How deeply to search for those exports.

  • unmount_before_update (bool) – Cause the component to be unmounted before each update. This option should only be used if the imported package fails to re-render when props change. Using this option has negative performance consequences since all DOM elements must be changed on each render. See #461 for more info.

  • symlink (bool) – Whether the web module should be saved as a symlink to the given file.

  • resolve_exports (bool | None) –

Return type

WebModule

reactpy.web.module.module_from_string(name, content, fallback=None, resolve_exports=None, resolve_exports_depth=5, unmount_before_update=False)[source]#

Load a WebModule whose content comes from a string.

Parameters
  • name (str) – The name of the package

  • content (str) – The contents of the web module

  • fallback (Any | None) – What to temporarily display while the module is being loaded.

  • resolve_imports – Whether to try and find all the named exports of this module.

  • resolve_exports_depth (int) – How deeply to search for those exports.

  • unmount_before_update (bool) – Cause the component to be unmounted before each update. This option should only be used if the imported package fails to re-render when props change. Using this option has negative performance consequences since all DOM elements must be changed on each render. See #461 for more info.

  • resolve_exports (bool | None) –

Return type

WebModule

class reactpy.web.module.WebModule(source: 'str', source_type: 'SourceType', default_fallback: 'Any | None', export_names: 'set[str] | None', file: 'Path | None', unmount_before_update: 'bool')[source]#

Bases: object

Parameters
  • source (str) –

  • source_type (SourceType) –

  • default_fallback (Any | None) –

  • export_names (set[str] | None) –

  • file (Path | None) –

  • unmount_before_update (bool) –

Return type

None

reactpy.web.module.export(web_module: reactpy.web.module.WebModule, export_names: str, fallback: Any | None = None, allow_children: bool = True) β†’ reactpy.core.types.VdomDictConstructor[source]#
reactpy.web.module.export(web_module: reactpy.web.module.WebModule, export_names: list[str] | tuple[str, ...], fallback: Any | None = None, allow_children: bool = True) β†’ list[reactpy.core.types.VdomDictConstructor]

Return one or more VDOM constructors from a WebModule

Parameters
  • export_names – One or more names to export. If given as a string, a single component will be returned. If a list is given, then a list of components will be returned.

  • fallback – What to temporarily display while the module is being loaded.

  • allow_children – Whether or not these components can have children.

utils#

__main__#

_option#

class reactpy._option.Option(name, default=<object object>, mutable=True, parent=None, validator=<function Option.<lambda>>)[source]#

Bases: Generic[reactpy._option._O]

An option that can be set using an environment variable of the same name

Parameters
  • name (str) –

  • default (_O) –

  • mutable (bool) –

  • parent (Option[_O] | None) –

  • validator (Callable[[Any], _O]) –

Return type

None

property name: str#

The name of this option (used to load environment variables)

property mutable: bool#

Whether this option can be modified after being loaded

property default: reactpy._option._O#

This option’s default value

subscribe(handler)[source]#

Register a callback that will be triggered when this option changes

Parameters

handler (Callable[[reactpy._option._O], None]) –

Return type

Callable[[reactpy._option._O], None]

is_set()[source]#

Whether this option has a value other than its default.

Return type

bool

set_current(new)[source]#

Set the value of this option

Raises a TypeError if this option is not Option.mutable.

Parameters

new (Any) –

Return type

None

set_default(new)[source]#

Set the value of this option if not Option.is_set()

Returns the current value (a la dict.set_default())

Parameters

new (reactpy._option._O) –

Return type

reactpy._option._O

reload()[source]#

Reload this option from its environment variable

Return type

None

unset()[source]#

Remove the current value, the default will be used until it is set again.

Return type

None

class reactpy._option.DeprecatedOption(*args, message, **kwargs)[source]#

Bases: reactpy._option.Option[reactpy._option._O]

An option that will warn when it is accessed

Parameters
  • args (Any) –

  • message (str) –

  • kwargs (Any) –

Return type

None

_warnings#

config#

ReactPy provides a series of configuration options that can be set using environment variables or, for those which allow it, a programmatic interface.

reactpy.config.REACTPY_DEBUG_MODE = Option(REACTPY_DEBUG_MODE=False)#

Get extra logs and validation checks at the cost of performance.

This will enable the following:

reactpy.config.REACTPY_CHECK_VDOM_SPEC = Option(REACTPY_CHECK_VDOM_SPEC=False)#

Checks which ensure VDOM is rendered to spec

For more info on the VDOM spec, see here: VDOM JSON Schema

reactpy.config.REACTPY_CHECK_JSON_ATTRS = Option(REACTPY_CHECK_JSON_ATTRS=False)#

Checks that all VDOM attributes are JSON serializable

The VDOM spec is not able to enforce this on its own since attributes could anything.

reactpy.config.REACTPY_WEB_MODULES_DIR = Option(REACTPY_WEB_MODULES_DIR=PosixPath('/tmp/tmp3xdh7acw'))#

The location ReactPy will use to store its client application

This directory MUST be treated as a black box. Downstream applications MUST NOT assume anything about the structure of this directory see reactpy.web.module for a set of publicly available APIs for working with the client.

reactpy.config.REACTPY_TESTING_DEFAULT_TIMEOUT = Option(REACTPY_TESTING_DEFAULT_TIMEOUT=5.0)#

A default timeout for testing utilities in ReactPy

reactpy.config.REACTPY_ASYNC_RENDERING = Option(REACTPY_ASYNC_RENDERING=False)#

Whether to render components asynchronously. This is currently an experimental feature.

future#

html#

Fragment

Document metadata

Content sectioning

Text content

Inline text semantics

Image and video

Embedded content

SVG and MathML

Scripting

Demarcating edits

Table content

Forms

Interactive elements

Web components

reactpy.html._(attributes, children, key, event_handlers)#

An HTML fragment - this element will not appear in the DOM

Parameters
  • attributes (VdomAttributes) –

  • children (Sequence[VdomChild]) –

  • key (Key | None) –

  • event_handlers (EventHandlerDict) –

Return type

VdomDict

reactpy.html.base(*attributes_and_children, **kwargs)#

Return a new <base> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.head(*attributes_and_children, **kwargs)#

Return a new <head> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

Return a new <link> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.meta(*attributes_and_children, **kwargs)#

Return a new <meta> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.style(*attributes_and_children, **kwargs)#

Return a new <style> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.title(*attributes_and_children, **kwargs)#

Return a new <title> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.address(*attributes_and_children, **kwargs)#

Return a new <address> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.article(*attributes_and_children, **kwargs)#

Return a new <article> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.aside(*attributes_and_children, **kwargs)#

Return a new <aside> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.footer(*attributes_and_children, **kwargs)#

Return a new <footer> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.header(*attributes_and_children, **kwargs)#

Return a new <header> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h1(*attributes_and_children, **kwargs)#

Return a new <h1> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h2(*attributes_and_children, **kwargs)#

Return a new <h2> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h3(*attributes_and_children, **kwargs)#

Return a new <h3> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h4(*attributes_and_children, **kwargs)#

Return a new <h4> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h5(*attributes_and_children, **kwargs)#

Return a new <h5> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.h6(*attributes_and_children, **kwargs)#

Return a new <h6> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.main(*attributes_and_children, **kwargs)#

Return a new <main> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.nav(*attributes_and_children, **kwargs)#

Return a new <nav> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.section(*attributes_and_children, **kwargs)#

Return a new <section> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.blockquote(*attributes_and_children, **kwargs)#

Return a new <blockquote> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.dd(*attributes_and_children, **kwargs)#

Return a new <dd> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.div(*attributes_and_children, **kwargs)#

Return a new <div> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.dl(*attributes_and_children, **kwargs)#

Return a new <dl> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.dt(*attributes_and_children, **kwargs)#

Return a new <dt> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.figcaption(*attributes_and_children, **kwargs)#

Return a new <figcaption> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.figure(*attributes_and_children, **kwargs)#

Return a new <figure> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.hr(*attributes_and_children, **kwargs)#

Return a new <hr> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.li(*attributes_and_children, **kwargs)#

Return a new <li> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.ol(*attributes_and_children, **kwargs)#

Return a new <ol> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.p(*attributes_and_children, **kwargs)#

Return a new <p> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.pre(*attributes_and_children, **kwargs)#

Return a new <pre> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.ul(*attributes_and_children, **kwargs)#

Return a new <ul> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.a(*attributes_and_children, **kwargs)#

Return a new <a> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.abbr(*attributes_and_children, **kwargs)#

Return a new <abbr> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.b(*attributes_and_children, **kwargs)#

Return a new <b> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.bdi(*attributes_and_children, **kwargs)#

Return a new <bdi> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.bdo(*attributes_and_children, **kwargs)#

Return a new <bdo> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.br(*attributes_and_children, **kwargs)#

Return a new <br> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.cite(*attributes_and_children, **kwargs)#

Return a new <cite> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.code(*attributes_and_children, **kwargs)#

Return a new <code> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.data(*attributes_and_children, **kwargs)#

Return a new <data> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.em(*attributes_and_children, **kwargs)#

Return a new <em> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.i(*attributes_and_children, **kwargs)#

Return a new <i> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.kbd(*attributes_and_children, **kwargs)#

Return a new <kbd> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.mark(*attributes_and_children, **kwargs)#

Return a new <mark> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.q(*attributes_and_children, **kwargs)#

Return a new <q> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.rp(*attributes_and_children, **kwargs)#

Return a new <rp> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.rt(*attributes_and_children, **kwargs)#

Return a new <rt> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.ruby(*attributes_and_children, **kwargs)#

Return a new <ruby> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.s(*attributes_and_children, **kwargs)#

Return a new <s> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.samp(*attributes_and_children, **kwargs)#

Return a new <samp> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.small(*attributes_and_children, **kwargs)#

Return a new <small> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.span(*attributes_and_children, **kwargs)#

Return a new <span> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.strong(*attributes_and_children, **kwargs)#

Return a new <strong> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.sub(*attributes_and_children, **kwargs)#

Return a new <sub> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.sup(*attributes_and_children, **kwargs)#

Return a new <sup> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.time(*attributes_and_children, **kwargs)#

Return a new <time> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.u(*attributes_and_children, **kwargs)#

Return a new <u> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.var(*attributes_and_children, **kwargs)#

Return a new <var> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.wbr(*attributes_and_children, **kwargs)#

Return a new <wbr> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.area(*attributes_and_children, **kwargs)#

Return a new <area> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.audio(*attributes_and_children, **kwargs)#

Return a new <audio> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.img(*attributes_and_children, **kwargs)#

Return a new <img> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.map(*attributes_and_children, **kwargs)#

Return a new <map> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.track(*attributes_and_children, **kwargs)#

Return a new <track> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.video(*attributes_and_children, **kwargs)#

Return a new <video> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.embed(*attributes_and_children, **kwargs)#

Return a new <embed> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.iframe(*attributes_and_children, **kwargs)#

Return a new <iframe> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.object(*attributes_and_children, **kwargs)#

Return a new <object> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.param(*attributes_and_children, **kwargs)#

Return a new <param> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.picture(*attributes_and_children, **kwargs)#

Return a new <picture> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.portal(*attributes_and_children, **kwargs)#

Return a new <portal> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.source(*attributes_and_children, **kwargs)#

Return a new <source> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.svg(*attributes_and_children, **kwargs)#

Return a new <svg> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.math(*attributes_and_children, **kwargs)#

Return a new <math> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.canvas(*attributes_and_children, **kwargs)#

Return a new <canvas> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.noscript(*attributes_and_children, **kwargs)#

Return a new <noscript> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.script(attributes, children, key, event_handlers)#

Create a new <script> element.

Warning

Be careful to sanitize data from untrusted sources before using it in a script. See the β€œNotes” for more details

This behaves slightly differently than a normal script element in that it may be run multiple times if its key changes (depending on specific browser behaviors). If no key is given, the key is inferred to be the content of the script or, lastly its β€˜src’ attribute if that is given.

If no attributes are given, the content of the script may evaluate to a function. This function will be called when the script is initially created or when the content of the script changes. The function may itself optionally return a teardown function that is called when the script element is removed from the tree, or when the script content changes.

Notes

Do not use unsanitized data from untrusted sources anywhere in your script. Doing so may allow for malicious code injection. Consider this insecure code:

my_script = html.script(f"console.log('{user_bio}');")

A clever attacker could construct user_bio such that they could escape the string and execute arbitrary code to perform cross-site scripting (XSS <https://en.wikipedia.org/wiki/Cross-site_scripting>`__). For example, what if user_bio were of the form:

'); attackerCodeHere(); ('

This would allow the following Javascript code to be executed client-side:

console.log(''); attackerCodeHere(); ('');

One way to avoid this could be to escape user_bio so as to prevent the injection of Javascript code. For example:

import json
my_script = html.script(f"console.log({json.dumps(user_bio)});")

This would prevent the injection of Javascript code by escaping the user_bio string. In this case, the following client-side code would be executed instead:

console.log("'); attackerCodeHere(); ('");

This is a very simple example, but it illustrates the point that you should always be careful when using unsanitized data from untrusted sources.

Parameters
  • attributes (VdomAttributes) –

  • children (Sequence[VdomChild]) –

  • key (Key | None) –

  • event_handlers (EventHandlerDict) –

Return type

VdomDict

reactpy.html.del_(*attributes_and_children, **kwargs)#

Return a new <del> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.ins(*attributes_and_children, **kwargs)#

Return a new <ins> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.caption(*attributes_and_children, **kwargs)#

Return a new <caption> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.col(*attributes_and_children, **kwargs)#

Return a new <col> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.colgroup(*attributes_and_children, **kwargs)#

Return a new <colgroup> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.table(*attributes_and_children, **kwargs)#

Return a new <table> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.tbody(*attributes_and_children, **kwargs)#

Return a new <tbody> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.td(*attributes_and_children, **kwargs)#

Return a new <td> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.tfoot(*attributes_and_children, **kwargs)#

Return a new <tfoot> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.th(*attributes_and_children, **kwargs)#

Return a new <th> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.thead(*attributes_and_children, **kwargs)#

Return a new <thead> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.tr(*attributes_and_children, **kwargs)#

Return a new <tr> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.button(*attributes_and_children, **kwargs)#

Return a new <button> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.fieldset(*attributes_and_children, **kwargs)#

Return a new <fieldset> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.form(*attributes_and_children, **kwargs)#

Return a new <form> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.input(*attributes_and_children, **kwargs)#

Return a new <input> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.label(*attributes_and_children, **kwargs)#

Return a new <label> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.legend(*attributes_and_children, **kwargs)#

Return a new <legend> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.meter(*attributes_and_children, **kwargs)#

Return a new <meter> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.option(*attributes_and_children, **kwargs)#

Return a new <option> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.output(*attributes_and_children, **kwargs)#

Return a new <output> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.progress(*attributes_and_children, **kwargs)#

Return a new <progress> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.select(*attributes_and_children, **kwargs)#

Return a new <select> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.textarea(*attributes_and_children, **kwargs)#

Return a new <textarea> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.details(*attributes_and_children, **kwargs)#

Return a new <details> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.dialog(*attributes_and_children, **kwargs)#

Return a new <dialog> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.menu(*attributes_and_children, **kwargs)#

Return a new <menu> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.menuitem(*attributes_and_children, **kwargs)#

Return a new <menuitem> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.summary(*attributes_and_children, **kwargs)#

Return a new <summary> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.slot(*attributes_and_children, **kwargs)#

Return a new <slot> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.html.template(*attributes_and_children, **kwargs)#

Return a new <template> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

logging#

reactpy.logging.ROOT_LOGGER = <Logger reactpy (INFO)>#

ReactPy’s root logger instance

sample#

svg#

reactpy.svg.a(*attributes_and_children, **kwargs)#

Return a new <a> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.animate(*attributes_and_children, **kwargs)#

Return a new <animate> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.animate_motion(*attributes_and_children, **kwargs)#

Return a new <animateMotion> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.animate_transform(*attributes_and_children, **kwargs)#

Return a new <animateTransform> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.circle(*attributes_and_children, **kwargs)#

Return a new <circle> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.clip_path(*attributes_and_children, **kwargs)#

Return a new <clipPath> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.defs(*attributes_and_children, **kwargs)#

Return a new <defs> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.desc(*attributes_and_children, **kwargs)#

Return a new <desc> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.discard(*attributes_and_children, **kwargs)#

Return a new <discard> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.ellipse(*attributes_and_children, **kwargs)#

Return a new <ellipse> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_blend(*attributes_and_children, **kwargs)#

Return a new <feBlend> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_color_matrix(*attributes_and_children, **kwargs)#

Return a new <feColorMatrix> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_component_transfer(*attributes_and_children, **kwargs)#

Return a new <feComponentTransfer> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_composite(*attributes_and_children, **kwargs)#

Return a new <feComposite> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_convolve_matrix(*attributes_and_children, **kwargs)#

Return a new <feConvolveMatrix> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_diffuse_lighting(*attributes_and_children, **kwargs)#

Return a new <feDiffuseLighting> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_displacement_map(*attributes_and_children, **kwargs)#

Return a new <feDisplacementMap> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_distant_light(*attributes_and_children, **kwargs)#

Return a new <feDistantLight> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_drop_shadow(*attributes_and_children, **kwargs)#

Return a new <feDropShadow> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_flood(*attributes_and_children, **kwargs)#

Return a new <feFlood> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_func_a(*attributes_and_children, **kwargs)#

Return a new <feFuncA> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_func_b(*attributes_and_children, **kwargs)#

Return a new <feFuncB> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_func_g(*attributes_and_children, **kwargs)#

Return a new <feFuncG> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_func_r(*attributes_and_children, **kwargs)#

Return a new <feFuncR> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_gaussian_blur(*attributes_and_children, **kwargs)#

Return a new <feGaussianBlur> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_image(*attributes_and_children, **kwargs)#

Return a new <feImage> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_merge(*attributes_and_children, **kwargs)#

Return a new <feMerge> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_merge_node(*attributes_and_children, **kwargs)#

Return a new <feMergeNode> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_morphology(*attributes_and_children, **kwargs)#

Return a new <feMorphology> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_offset(*attributes_and_children, **kwargs)#

Return a new <feOffset> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_point_light(*attributes_and_children, **kwargs)#

Return a new <fePointLight> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_specular_lighting(*attributes_and_children, **kwargs)#

Return a new <feSpecularLighting> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_spot_light(*attributes_and_children, **kwargs)#

Return a new <feSpotLight> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_tile(*attributes_and_children, **kwargs)#

Return a new <feTile> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.fe_turbulence(*attributes_and_children, **kwargs)#

Return a new <feTurbulence> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.filter(*attributes_and_children, **kwargs)#

Return a new <filter> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.foreign_object(*attributes_and_children, **kwargs)#

Return a new <foreignObject> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.g(*attributes_and_children, **kwargs)#

Return a new <g> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.hatch(*attributes_and_children, **kwargs)#

Return a new <hatch> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.hatchpath(*attributes_and_children, **kwargs)#

Return a new <hatchpath> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.image(*attributes_and_children, **kwargs)#

Return a new <image> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.line(*attributes_and_children, **kwargs)#

Return a new <line> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.linear_gradient(*attributes_and_children, **kwargs)#

Return a new <linearGradient> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.marker(*attributes_and_children, **kwargs)#

Return a new <marker> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.mask(*attributes_and_children, **kwargs)#

Return a new <mask> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.metadata(*attributes_and_children, **kwargs)#

Return a new <metadata> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.mpath(*attributes_and_children, **kwargs)#

Return a new <mpath> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.path(*attributes_and_children, **kwargs)#

Return a new <path> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.pattern(*attributes_and_children, **kwargs)#

Return a new <pattern> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.polygon(*attributes_and_children, **kwargs)#

Return a new <polygon> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.polyline(*attributes_and_children, **kwargs)#

Return a new <polyline> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.radial_gradient(*attributes_and_children, **kwargs)#

Return a new <radialGradient> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.rect(*attributes_and_children, **kwargs)#

Return a new <rect> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.script(*attributes_and_children, **kwargs)#

Return a new <script> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.set(*attributes_and_children, **kwargs)#

Return a new <set> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.stop(*attributes_and_children, **kwargs)#

Return a new <stop> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.style(*attributes_and_children, **kwargs)#

Return a new <style> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.svg(*attributes_and_children, **kwargs)#

Return a new <svg> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.switch(*attributes_and_children, **kwargs)#

Return a new <switch> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.symbol(*attributes_and_children, **kwargs)#

Return a new <symbol> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.text(*attributes_and_children, **kwargs)#

Return a new <text> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.text_path(*attributes_and_children, **kwargs)#

Return a new <textPath> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.title(*attributes_and_children, **kwargs)#

Return a new <title> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.tspan(*attributes_and_children, **kwargs)#

Return a new <tspan> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.use(*attributes_and_children, **kwargs)#

Return a new <use> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

reactpy.svg.view(*attributes_and_children, **kwargs)#

Return a new <view> element represented by a VdomDict.

Parameters
  • attributes_and_children (Any) –

  • kwargs (Any) –

Return type

reactpy.core.types.VdomDict

types#

Exports common types from:

utils#

class reactpy.utils.Ref(initial_value=<object object>)[source]#

Bases: Generic[reactpy.utils._RefValue]

Hold a reference to a value

This is used in imperative code to mutate the state of this object in order to incur side effects. Generally refs should be avoided if possible, but sometimes they are required.

Notes

You can compare the contents for two Ref objects using the == operator.

Parameters

initial_value (_RefValue) –

Return type

None

current#

The present value

set_current(new)[source]#

Set the current value and return what is now the old value

This is nice to use in lambda functions.

Parameters

new (reactpy.utils._RefValue) –

Return type

reactpy.utils._RefValue

reactpy.utils.vdom_to_html(vdom)[source]#

Convert a VDOM dictionary into an HTML string

Only the following keys are translated to HTML:

  • tagName

  • attributes

  • children (must be strings or more VDOM dicts)

Parameters

vdom (reactpy.core.types.VdomDict) – The VdomDict element to convert to HTML

Return type

str

reactpy.utils.html_to_vdom(html, *transforms, strict=True)[source]#

Transform HTML into a DOM model. Unique keys can be provided to HTML elements using a key=... attribute within your HTML tag.

Parameters
  • html (str) – The raw HTML as a string

  • transforms (Callable[[reactpy.core.types.VdomDict], Any]) – Functions of the form transform(old) -> new where old is a VDOM dictionary which will be replaced by new. For example, you could use a transform function to add highlighting to a <code/> block.

  • strict (bool) – If True, raise an exception if the HTML does not perfectly follow HTML5 syntax.

Return type

reactpy.core.types.VdomDict

exception reactpy.utils.HTMLParseError[source]#

Bases: lxml.etree.LxmlSyntaxError

Raised when an HTML document cannot be parsed using strict parsing.

reactpy.utils.del_html_head_body_transform(vdom)[source]#

Transform intended for use with html_to_vdom.

Removes <html>, <head>, and <body> while preserving their children.

Parameters

vdom (reactpy.core.types.VdomDict) – The VDOM dictionary to transform.

Return type

reactpy.core.types.VdomDict

widgets#

reactpy.widgets.image(format, value='', attributes=None)[source]#

Utility for constructing an image from a string or bytes

The source value will automatically be encoded to base64

Parameters
  • format (str) –

  • value (str | bytes) –

  • attributes (dict[str, Any] | None) –

Return type

VdomDict

reactpy.widgets.use_linked_inputs(attributes, on_change=<function <lambda>>, cast=<function <lambda>>, initial_value='', ignore_empty=True)[source]#

Return a list of linked inputs equal to the number of given attributes.

Parameters
  • attributes (collections.abc.Sequence[dict[str, Any]]) – That attributes of each returned input element. If the number of generated inputs is variable, you may need to assign each one a key by including a "key" in each attribute dictionary.

  • on_change (Callable[[reactpy.widgets._Value], None]) – A callback which is triggered when any input is changed. This callback need not update the β€˜value’ field in the attributes of the inputs since that is handled automatically.

  • cast (reactpy.widgets._CastFunc[reactpy.widgets._Value]) – Cast the β€˜value’ of changed inputs that is passed to on_change.

  • initial_value (str) – Initialize the β€˜value’ field of the inputs.

  • ignore_empty (bool) – Do not trigger on_change if the β€˜value’ is an empty string.

Return type

list[reactpy.core.types.VdomDict]