Getting Started in Python

See the doc-step-by-step repository on git.eminjenv.nl for a more extensive guide that takes you by the hand from the very beginning. It explains how to install all prerequisites, how to write your first Extraction Plugin in Python, how to test it and how to run it.

This section assumes you use the same setup as is used in the Extraction Plugin Examples and have installed all prerequisites.

Installation

To install the Python Extraction Plugins SDK, run:

pip install hansken-extraction-plugin

Building and running

If you just want to build and test a python plugin code, use:

tox

This will show the test results for the plugin and a wheel distribution is created in the dist/ directory.

To test the plugin running in a docker image:

tox -e integration

To serve the plugin manually:

serve_plugin -vvv <file> <port>

Where file is the Python implementation of the plugin, and port is the port on which the plugin is served. The command line option -vvv prints debug information to standard output.

For more information, see Testing.

Building a docker image for a Python plugin

Make sure that the Extraction Plugins SDK is installed as well as Docker. Then, build your plugin container image using the following command:

build_plugin PLUGIN_FILE DOCKER_FILE_DIRECTORY [DOCKER_IMAGE_NAME]

For example:

build_plugin plugin/chatplugin.py . extraction-plugins/chatplugin

This will generate a plugin image:

  • The extraction plugin is added to your local image registry (docker images),

  • Note that DOCKER_IMAGE_NAME is optional and will default to extraction-plugin/PLUGINID, e.g. extraction-plugin/nfi.nl/extract/chat/whatsapp,

  • The image is tagged with two tags: latest, and your plugin version.

To verify that the image has been built, type the following command to view all local images:

docker images