pyxley package

Submodules

pyxley.react_template module

class pyxley.react_template.ReactComponent(name, path, element_id, props={}, static_path='', alias=None)

Bases: pyxley.react_template.ReactTemplate

Class to generate javascript from parameters.

This class create a javascript file by compiling a JSX string containing React components. A single parent component is rendered and sub-components are passed into the component as props.

Parameters:
  • name (str) – name of the ReactComponent to create.
  • path (str) – location of the javascript file containing the component.
  • element_id (str) – html element id.
  • props (dict) – properties of the react component to render.
  • static_path (str) – output file destination.
class pyxley.react_template.ReactTemplate(template, template_args, path)

Bases: object

Base React class.

This class handles the basic transformation of the React jsx code. It takes a dictionary of options, renders the template, and writes the transformed javascript file.

Parameters:
  • template (str) – jinja2 template for the react jsx code.
  • template_args (dict) – options to be populated in the template.
  • path (str) – path of the file to create.
to_js()
write_to_file(s)
pyxley.react_template.format_props(props, prop_template='{{k}} = { {{v}} }', delim='\n')

Formats props for the React template.

Parameters:props (dict) – properties to be written to the template.
Returns:Two lists, one containing variable names and the other containing a list of props to be fed to the React template.

pyxley.ui module

class pyxley.ui.SimpleComponent(layout, src_file, component_id, props)

Bases: object

Simple class for rendering a single component.

Rather than requiring a collection of filters and charts, this function will render a single react component with props passed as a dictionary.

Parameters:
  • layout (str) – Type of react component to create.
  • src_file (str) – javascript file containing the component.
  • component_id (str) – html element id.
  • props (dict) – props for the component.
render(path)

Render the component to a javascript file.

class pyxley.ui.UIComponent(component_type, options, route_func)

Bases: object

Base React UI component.

Every UI component is derived from this component. Both charts and filters inherit these methods. This class allows the chart to register the endpoint with the flask application.

Parameters:
  • component_type (str) – Type of component to build.
  • options (dict) – options specific to the component type.
  • route_func (function) – endpoint function.
register_route(app)

Register the api route function with the app.

class pyxley.ui.UILayout(layout, component_id='component_id', src_file='pyxley')

Bases: object

Simple UI layout.

This class handles the construction of a single javascript file based on the inputs provided. It aggregates the properties specified over the different charts and filters and creates a single set of props.

This relies on the creation of a single React component that is comprised of charts and filters. An example can be found at https://github.com/stitchfix/pyxleyJS/blob/master/src/layouts.js

Parameters:
  • layout (str) – name of react component to render.
  • src_file (str) – location of javascript containing the component.
  • component_id (str) – html element id.
add_chart(component)

Add a chart to the layout.

add_filter(component, filter_group='pyxley-filter')

Add a filter to the layout.

assign_routes(app)

Register routes with the app.

build_props()

Build the props dictionary.

render_layout(app, path, alias=None)

Write to javascript.

pyxley.ui.register_layouts(layouts, app, url='/api/props/', brand='Pyxley')

register UILayout with the flask app

create a function that will send props for each UILayout

Parameters:
  • layouts (dict) – dict of UILayout objects by name
  • app (object) – flask app
  • url (string) – address of props; default is /api/props/

Module contents