Skip to main content

Toucan Toco Connectors

Project description

Pypi-v Pypi-pyversions Pypi-l Pypi-wheel GitHub Actions Coverage

Toucan Connectors

Toucan Toco data connectors are plugins to the Toucan Toco platform, configured with dictionaries (cf. DataSource class) and returning Pandas DataFrames.

Setup

In order to work you need make and Python 3.8 (consider running pip install -U pip setuptools if needed) :warning: On linux, you're going to need bindings for unixodbc to install pyodbc from the requirements, and to install that (using apt), just follow:

sudo apt-get update
sudo apt-get install unixodbc-dev

Now, you can then install:

  • the main dependencies by typing pip install -e .
  • the test requirements by typing pip install -r requirements-testing.txt

You should be able to run basic tests pytest tests/test_connector.py

Consider installing pre-commit to profit form linting hooks:

$ pip install pre-commit
$ pre-commit install

:warning: To test and use mssql (and azure_mssql) you need to install the Microsoft ODBC driver for SQL Server for Linux or MacOS

:warning: On macOS, to test the postgres connector, you need to install postgresql by running for instance brew install postgres. You can then install the library with env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip install psycopg2

Testing a connector

If you want to run the tests for another connector, you can install the extra dependencies (e.g to test MySQL just type pip install -e ".[mysql]") Now pytest tests/mysql should run all the mysql tests properly.

If you want to run the tests for all the connectors you can add all the dependencies by typing pip install -e ".[all]" and make test.

Adding a connector

To generate the connector and test modules from boilerplate, run:

$ make new_connector type=mytype

mytype should be the name of a system we would like to build a connector for, such as MySQL or Hive or Magento.

Step 1 : Tests

Open the folder in tests for the new connector. You can start writing your tests before implementing it.

Some connectors are tested with calls to the actual data systems that they target, for example elasticsearch, mongo, mssql. Other are tested with mocks of the classes or functions returning data that you are wrapping (see : HttpAPI, or microstrategy).

If you have a container for your target system, please do not hesitate to add a docker image in the docker-compose.yml. You can then use the fixture service_container to automatically start the docker and shut it down for you!

:warning: The test runner assumes you have all the docker images locally, if not please run pytest with --pull to retrieve them

Step 2 : New connector

Open the folder mytype in toucan_connectors for your new connector and create your classes

import pandas as pd

# Careful here you need to import ToucanConnector from the deep path, not the __init__ path.
from toucan_connectors.toucan_connector import ToucanConnector, ToucanDataSource


class MyTypeDataSource(ToucanDataSource):
    """Model of my datasource"""
    query: str


class MyTypeConnector(ToucanConnector):
    """Model of my connector"""
    data_source_model: MyTypeDataSource

    host: str
    port: int
    database: str

    def _retrieve_data(self, data_source: MyTypeDataSource) -> pd.DataFrame:
        """how to retrieve a dataframe"""

Please add your connector in toucan_connectors/__init__.py. The key is what we call the type of the connector, which is basically like an id used to retrieve it.

CONNECTORS_CATALOGUE = {
  ...,
  'MyType': 'mytype.mytype_connector.MyTypeConnector',
  ...
}

You can now generate and edit the documentation page for your connector:

PYTHONPATH=. python doc/generate.py MyTypeConnector > doc/mytypeconnector.md

Step 3 : Register your connector

Add the main requirements to the setup.py in the extras_require dictionary:

extras_require = {
    ...
    'mytype': ['my_dependency_pkg1==x.x.x', 'my_dependency_pkg2>=x.x.x']
}

If you need to add testing dependencies, add them to the requirements-testing.txt file.

Step 4 : Create a pull request

Make sure your new code is properly formatted by typing make lint. If it's not, please use make format! You can now create a pull request!

Project details


Release history Release notifications | RSS feed

This version

1.2.7

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toucan_connectors-1.2.7.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toucan_connectors-1.2.7-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file toucan_connectors-1.2.7.tar.gz.

File metadata

  • Download URL: toucan_connectors-1.2.7.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

File hashes

Hashes for toucan_connectors-1.2.7.tar.gz
Algorithm Hash digest
SHA256 ef5e734bf1330194fef9e893c3c467ec50949eaa896366a528afca5fc016bd5d
MD5 3b0d4f597be53a81a0cc96754cafcb01
BLAKE2b-256 aa8e1a2183583b309f3ccbbbe3f4d28581d8e4e7f9f860bc44eef98c04d6cfd9

See more details on using hashes here.

File details

Details for the file toucan_connectors-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: toucan_connectors-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

File hashes

Hashes for toucan_connectors-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 632683925bd7382f7d0cd52603e36fcb6071acbbc3ec629d24fd75d7f1deb676
MD5 0d28d4933c08d2108808da4d2cd3f762
BLAKE2b-256 b1feed2632324aaff6992008f3b0d6d1c233eae032fd960ff5c5942a64000218

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page