Data Interface

Data is key for Visualisation so this is why Epyk provides ways to retrieve / connect the data.

Data Transformers

Those will transform the data to fit the format expected by the various containers. Basically this is the format expected in the HTML components in the __init__ or in the build method.

Those functions can be used from the page object from page.data or directly from the module by using pk.

This module should be moved to a dedicated package in future releases to make the use on the backend side lighter.

Interface Documentation

class epyk.core.data.Data.DataJs(page: PageModel)
list(js_code: str, data)

Transform a Python object to a JavaScript list.

Parameters:
  • js_code – The Javascript variable name

  • data – Object passed to the Javascript layer

number(js_code: str, value)

Transform a Python number to a JavaScript one.

Parameters:
  • js_code – The Javascript variable name

  • value – Object passed to the Javascript layer

object(js_code: str, value: float)

Transform a Python object to a JavaScript object.

Parameters:
  • js_code – The Javascript variable name

  • value – Object passed to the Javascript layer

record(js_code: Optional[str] = None, data=None) DataGlobal

Interface to transform Python records to Javascript objects.

This will allow interactivity of the various HTML components.

Usage:

js_data = page.data.js.record(js_code="myData", data=randoms.languages) # Create JavaScript data
filter1 = js_data.filterGroup("filter1") # Add a filter object

# Add a dropdown box to drive the data changes in the charts
select = page.ui.select([
  {"value": 'name', 'name': 'name'}, {"value": 'type', 'name': 'code'}], options={"empty_selected": False})

# Create HTML charts
bar = page.ui.charts.chartJs.bar(randoms.languages, y_columns=["rating", 'change'], x_axis='name')
pie = page.ui.charts.chartJs.pie(randoms.languages, y_columns=['change'], x_axis='name')

select.change([
  bar.build(filter1.group().sumBy(['rating', 'change'], select.dom.content), options={"x_axis": select.dom.content}),
  pie.build(filter1.group().sumBy(['change'], select.dom.content), options={"x_axis": select.dom.content}),
])
Parameters:
  • js_code – Optional. The Javascript variable name

  • data – Object passed to the Javascript layer

server(hostname: str, port: int = 8080) ServerConfig

Configuration data for server interaction.

This will only help on centralising the configuration in the final page.

Parameters:
  • hostname – The server hostname

  • port – Optional. The server port

class epyk.core.data.Data.DataSrc(page: Optional[PageModel] = None)
property bb: C3

Interface to Billboard data transformation.

This will convert Python object to input data for Billboard charts.

property c3: C3

Interface to C3 data transformation.

This will convert Python object to input data for C3 charts.

property chartJs: ChartJs

Interface to chartJs data transformation.

This will convert Python object to input data for chartJs charts.

property db

Interface to the internal database wrapper.

Return type:

DataDb.DataDb

from_cache(code: str, is_secured: bool = False, report_name: Optional[str] = None)

Loads data from a cached files.

Parameters:
  • code – The code for the data

  • is_secured – Optional, boolean to set if the file should be secured. Default False

  • report_name – Optional. the environment in which cache are stored. Default current one

Returns:

Return the data

from_file(filename, isSecured=False, report_name=None)

Return the file.

Parameters:
  • filename – The filename.

  • isSecured – Optional. Check if the file is secured or not.

  • report_name – Optional. The environment with the file.

Returns:

The file object

from_get(url, data=None, code=None)
from_source(http_data, file_name, func_name='getData', report_name=None, folder='sources', path=None)

Returns data from a internal data service defined in the sources folder.

Parameters:
  • http_data – The input data for the service

  • file_name – The service file name

  • func_ame – Optional, the function name in the service. Default getData

  • report_name – Optional, the report name. Default the current one

  • folder – Optional, the folder with the services. Default sources

  • path – Optional, the path to be added to the python system path

property google: Google

Interface to Google data transformation.

This will convert Python object to input data for Google charts.

grpc(service_name, path, module, host='localhost', port=50051)

Interface to a GRPC server.

Usage:

grpc = page.data.grpc(serviceName="GreeterStub", module="helloworld_pb2_grpc", path="")
data = grpc.imp("helloworld_pb2").HelloRequest(name="Test")
print(grpc.request("SayHello", data))

Related Pages:

Parameters:
  • service_name – The Service name (the class name in the python module)

  • path – The path with the GRPC features

  • module – The python module name for the service

  • host – The service host name (e.g localhost)

  • port – The service port

Returns:

A GRPC wrapped object

Return type:

DataGrpc.DataGrpc

property js: DataJs

Interface to standard JavaScript transformation.

property nvd3: NVD3

Interface to NVD3 data transformation.

This will convert Python object to input data for NVD3 charts.

pdf(filename, path=None)

Read a pdf file

This will require an external module PyPDF2.

Usage:

data = page.data.pdf("document.pdf", r"")
data.getPage(0)

Related Pages:

Parameters:
  • filename – The pdf file name

  • path – The file path

Returns:

A pdf object from PyPDF2

property plotly: Plotly

Interface to Plotly data transformation.

This will convert Python object to input data for Plotly charts.

rest(url, data=None, method=None, encoding='utf-8', headers=None, unverifiable=False, proxy=None)

Interface to a REST server.

Test with a online server can be done here https://jsonplaceholder.typicode.com/

Usage:

page.data.rest("https://jsonplaceholder.typicode.com/posts/1", method="PUT")

Related Pages:

Parameters:
  • url – The REST service url

  • data – The input data for the service

rpc(url, data=None, headers=None, is_secured=False)

Interface to a RPC server.

This is using the external python package jsonrpcclient (https://jsonrpcclient.readthedocs.io/en/latest/)

Related Pages:

Parameters:
  • url – The RPC service url

  • data – The input data for the service

rss(url, proxy=None, method='GET')

Entry point to retrieve RSS feeds.

This module will require beautifulsoup4 as external package

Usage:

xml_soup = rptObj.data.rss("http://feeds.reuters.com/reuters/businessNews")
for title in xml_soup.findAll('title'):
  print(title)

Related Pages:

Parameters:
  • url – The url of the html page

  • method – Optional, The request method. Default method GET

Returns:

A xml object

save_cache(data, code, is_secured: bool = False, if_missing: bool = True)

Temporary files are saved in a pickle manner in order to avoid having to parse those files again.

Parameters:
  • data – The data to be saved.

  • code – The code for the data.

  • is_secured – Optional. boolean to set if the file should be secured. Default False.

  • if_missing – Optional. boolean to set the fact that caches are only saved if missing.

soap(wsdl)

Interface to a SOAP server.

This function will require an external python package zeep to use SOAP

Usage:

soap = page.data.soap("http://www.soapclient.com/xml/soapresponder.wsdl")
soap.Method1('Zeep', 'is cool')

Related Pages:

Parameters:

wsdl – The wsdl service url

Return type:

zeep.service

Returns:

The SOAP services

socket(data, host='localhost', port=5000, encoding='utf-8')
Parameters:
  • data – The input data for the service

  • host – The service host name (e.g localhost)

  • port – The service port

  • encoding

property vis: Vis

Interface to Vis data transformation.

This will convert Python object to input data for Vis charts.

webscrapping(url, parser='html.parser', proxy=None, method=None)

Entry point to retrieve data from any website.

This module will require beautifulsoup4 as external package

Usage:

page.data.webscrapping("https://www.w3schools.com/colors/default.asp")
xml_soup.findAll('title')

Related Pages:

Parameters:
  • url – The url of the html page

  • parser – The output data parser

  • proxy

  • method

Returns:

A xml object