API

React Module

class react.React(opts)[source]

Wrap basic functionality to render react views. The only thing it cares is that there is a global.RenderToString(opts) function defined in the pre-loaded js libs. This render function renders a component, matches a route, etc and returns the rendered view or a json with extra data.

Parameters:opts (dict) – Dict of parameters the js render function will receive, it must be serializable with json
as_json()[source]

Serialize opts into a json. This is used internally and can be overridden to provide a faster json serializer.

Returns:Opts in json format
Return type:str
build_js_script()[source]
Returns:The call to the JS render function
Return type:str
render()[source]
Returns:Result of the JS render call
Return type:str
Raises:react.excepts.V8Error – if there was an error running the JS script
static to_dict(json_str)[source]

De-serialize a json string into a python dict.

Parameters:json_str (str) – String to convert into dict
Returns:Received string in dict format
Return type:dict
static to_json(data)[source]

Serialize a dict into a json.

Parameters:data (dict or str) – Dict to convert into JSON
Returns:Received data in json format
Return type:str
react.set_up()[source]

Setup V8 machinery and define some basic variables into the global V8 context. Should be called once in the app lifetime.

Raises:react.excepts.V8Error – if there was an error running the JS script. This should usually not be handled

Utils Module

react.utils.set_up()[source]

Setup V8 machinery. Should be called once in the app lifetime, usually through react.set_up().

Raises:react.excepts.V8Error – if there was an error. This should usually not be handled
react.utils.load_libs(scripts_paths)[source]

Load JavaScript libs into the global V8 context for later use.

Parameters:scripts_paths (list) – List of javascript files
Raises:react.excepts.V8Error – if there was an error running the JS script
react.utils.run_script(script)[source]

Execute a script (i.e. a function call) into the global V8 context.

Parameters:script (str) – Code to execute within the V8 context
Raises:react.excepts.V8Error – if there was an error running the JS script

Excepts Module

exception react.excepts.V8Error[source]

Base error for all V8 related errors

exception react.excepts.V8JSError[source]

Error raised when a JS script fails to compile or run. The message contains an explanation of the cause of the error

exception react.excepts.V8MemoryError[source]

Error raised when an allocation fails, this usually means out of memory

exception react.excepts.V8UnknownError[source]

Unpredicted error