- Interpret the script in the same process for validation and describe requests.
- Interpret the script in the same process and invoke the function in a sub process for fetch data requests.
Connector Feature Support
Connector support for specific features is shown in the following table.Install the Python Connector
The python connector is available as a Docker image only. Docker must be installed on the Self-Service Analytics server running the Python connector.Download and Install the Docker Image in a Linux Environment
To download the Docker image:<RELEASE_TAG> in this repo: https://hub.docker.com/r/insightsoftware/zoomdata-edc-python/tags.
Use the docker run command to run the Python connector.
In the example below, the docker run command runs the setup on the same machine that has both the connector installed and other Self-Service Analytics services installed using the bootstrap script:
Adjust the command to work with your specific network configuration.
- Consul host is passed to Python Connector using the
DISCOVERY_REGISTRY_HOSTenvironment variable. - Because the container network in this case is connected to the host machine’s network (due to
--network=host), Consul is accessed onlocalhost. - Use
--name paramto assign a meaningful name to the container.--detachruns the container in the background and prints the container ID. - See docker documentation for more information on
docker runarguments.
Run the Python Connector on Non-Linux Servers
Define a networking configuration that:- Runs the connector inside a container that can access the Consul host and register with Consul.
- Allows other Self-Service Analytics services to access the connector running inside the container.
--env DISCOVERY_REGISTRY_HOST=localhost --network=host is not suitable. You’ll need to make sure that Consul listens on external port 8500, and takes its hostname. Additionally, you may need to use the --expose 8153 argument to expose the port that the Python Connector listens on. Also, you can use the --hostname argument to control the value of the service address that will be registered in Consul for Python Connector. Putting it together:
Verify the Installation
To verify correct installation of the Python connector, run the following command shortly after Self-Service Analytics starts:passing.
After that, log in to Self-Service Analytics create a new connection. Python should be available in the Connection Type list.
View Python Logs
To view the Python connector’s logs use thedocker logs command:
Python Packages
The Docker image is shipped with thepython3-pip package installed. This includes preinstalled pip packages of numpy, pandas, requests, and jep. To install additional pip packages, use the ADDITIONAL_PYTHON_LIBS environment variable when running the container.
boto3 and python-dateutil packages inside the container.
For more information on using the Python connector and how it works, see Use the Python Connector.
Use the Python Connector
You can use the Python connector using arbitrary Python scripts as connection parameter.Python Script Conventions
Data sources are resolved from Python script using the following conventions:- Each function definition is a separate data source
- Private functions (that start with an underscore
_) are not resolved as a data source
- Pandas dataframes.
- Dictionaries: The key is a string (column name) and values a list:
return {"column1": [1, 2, 3], "column2": ["one", "two", "three"]}. - List of dictionaries: return
[{"column1": 1, "column2": "one"}, {"column1": 2, "column2": "two"}]. - List of lists:
return [[1, 2], [3, 4]]. Each enclosed list resolves as a row. - List:
return [1, 2, 3, 4]. Resolves as a single column with index 1. - Single value of any of supported types:
return 1ORreturn decimal.Decimal("3.14")
Conversion Values
The connector applies the following rules when reading values:Python Script Writing Tips
Avoid using top level statements Top level statement are executed in a single thread for all users. You can add function calls in a top level statement to validate a connection, but do not call functions when you save your script. See How the Connector Works. Avoid overriding internal names Python is used within your environment to invoke data source functions and convert data. Since this code is executed in the same namespace as your scripts, if you try to override the names listed below, you may receive unexpected results. Avoid using the following names in your code:__convert__convert_list_of_dicts_to_dict_of_listsf__fork__emulateall_functions
pandasnumbersdatetimemultiprocessingqueueinspecttypes
/opt/zoomdata/logs/opt/zoomdata/temp/opt/zoomdata/lib/opt/zoomdata/wrappers
How the Connector Works
Python code is executed using JEP to interpret Python code in the same process where the Java app is running. To circumvent some Global Interpreter Lock issues in Python, some queries use processed based parallelism. Based on the request type, the connector functions in one of two ways:- Interpret the script in the same process for validation and describe requests.
- Interpret the script in the same process and invoke the function in a sub process for fetch data requests.
side_effect as an entity for the source will return an error such as:
Logging
Outputs of your Python scripts are not preserved. Statements such asprint("Message") to write data to stdout or stderr will not be retained.