1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
%global _empty_manifest_terminate_build 0
Name: python-toucan-connectors
Version: 4.4.1
Release: 1
Summary: Toucan Toco Connectors
License: BSD
URL: https://pypi.org/project/toucan-connectors/
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/77/a2/b1d5e2392441b6d56945253a9bfc5e0417bf6c50c7ca420009435b9c5980/toucan_connectors-4.4.1.tar.gz
BuildArch: noarch
Requires: python3-Authlib
Requires: python3-aiohttp
Requires: python3-cached-property
Requires: python3-Jinja2
Requires: python3-jq
Requires: python3-pydantic
Requires: python3-requests
Requires: python3-tenacity
Requires: python3-toucan-data-sdk
Requires: python3-adobe-analytics
Requires: python3-bearer
Requires: python3-oauthlib
Requires: python3-requests-oauthlib
Requires: python3-awswrangler
Requires: python3-pyodbc
Requires: python3-clickhouse-driver
Requires: python3-dataiku-api-client
Requires: python3-elasticsearch
Requires: python3-facebook-sdk
Requires: python3-graphql-client
Requires: python3-google-api-python-client
Requires: python3-oauth2client
Requires: python3-googleads
Requires: python3-google-cloud-bigquery[bqstorage,pandas]
Requires: python3-PyMySQL
Requires: python3-gspread
Requires: python3-PyHive[hive]
Requires: python3-xmltodict
Requires: python3-pymongo
Requires: python3-tctc-odata
Requires: python3-cx-Oracle
Requires: python3-openpyxl
Requires: python3-psycopg2
Requires: python3-redshift-connector
Requires: python3-lxml
Requires: python3-PyJWT
Requires: python3-simplejson
Requires: python3-pyhdb
Requires: python3-zeep
Requires: python3-snowflake-connector-python
Requires: python3-pyarrow
Requires: python3-toucan-client
Requires: python3-peakina
Requires: python3-hubspot-api-client
%description
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://github.com/ToucanToco/toucan-connectors/actions?query=workflow%3ACI)
[](https://sonarcloud.io/dashboard?id=ToucanToco_toucan-connectors)
# Toucan Connectors
[Toucan Toco](https://toucantoco.com/fr/) data connectors are plugins to the Toucan Toco platform. Their role is to return [Pandas DataFrames](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) from many different sources.

Each connector is dedicated to a single type of source (PostrgeSQL, Mongo, Salesforce, etc...) and is made of two classes:
- `Connector` which contains all the necessary information to *use a data provider* (e.g. hostname, auth method and details, etc...).
- `DataSource` which contains all the information to *get a dataframe* (query, path, etc...) using the `Connector` class above.
The Toucan Toco platform instantiates these classes using values provided by Toucan admin and app designers, it then uses the following methods to get data and metadata:
- `Connector._retrieve_data` returning an instance of `pandas.DataFrame`, method used to return data to a Toucan Toco end user
- `Connector.get_slice` returning an instance of `DataSlice`, method used to return data to a Toucan Toco application designer when building a query.
- `Connector.get_status` returning an instance of `ConnectorStatus`, method used to inform an admin or Toucan Toco application designer of the status of its connection to a third party data service. Is it reachable from our servers? Are the authentication details and method working? etc...
## Installing for development
We use `poetry` for packaging and development. Use the following command to install the project for development:
```
poetry install -E all
```
## Dependencies
This project uses `make` and `Python 3.8`. Install the main dependencies :
```bash
pip install -e .
```
We are using the `setuptools` construct `extra_requires` to define each connector's dependencies separately. For example to install the MySQL connector dependencies:
```bash
pip install -e ".[mysql]"
```
There is a shortcut called `all` to install all the dependencies for all the connectors. I do not recommend that you use this as a contributor to this package, but if you do, use the section below to install the necessary system packages.
```bash
pip install -e ".[all]"
```
You may face issues when instally the repo locally due to dependencies.
That's why a dev container is available to be used with visual studio.
Refer to [this doc](https://code.visualstudio.com/docs/remote/containers) to use it.
### System packages
Some connectors dependencies require specific system packages. As each connector can define its dependencies separatly you do not need this until you want to use these specific connectors.
#### ODBC
On `linux`, you're going to need bindings for `unixodbc` to install `pyodbc` from the requirements, and to install that (using apt), just follow:
```bash
sudo apt-get update
sudo apt-get install unixodbc-dev
```
#### MSSSQL
To test and use `mssql` (and `azure_mssql`) you need to install the Microsoft ODBC driver for SQL Server for
[Linux](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15)
or [MacOS](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15)
#### PostgreSQL
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
We are using `pytest` and various packages of its ecosystem.
To install the testing dependencies, run:
```bash
pip install -r requirements-testing.txt
```
As each connector is an independant plugin, its tests are written independently from the rest of the codebase.
Run the tests for a specifc connector (`http_api` in this example) like this:
```bash
pytest tests/http_api
```
Note: running the tests above implies that you have installed the specific dependencies of the `http_api` connector (using the `pip install -e .[http_api]` command)
Our CI does run all the tests for all the connectors, like this:
```
pip install -e ".[all]"
make test
```
Some connectors are tested using mocks (cf. `trello`), others are tested by making calls to data providers (cf. `elasticsearch`) running on the system in docker containers. The required images are in the `tests/docker-compose.yml` file, they need to be pulled (cf. `pytest --pull`) to run the relevant tests.
## Contributing
This is an open source repository under the [BSD 3-Clause Licence](https://github.com/ToucanToco/toucan-connectors/blob/master/LICENSE). The Toucan Toco tech team are the maintainers of this repository, we welcome contributions.
At the moment the main use of this code is its integration into Toucan Toco commercially licenced software, as a result our dev and maintenance efforts applied here are mostly driven by Toucan Toco internal priorities.
The starting point of a contribution should be an [Issue](https://github.com/ToucanToco/toucan-connectors/issues), either one you create or an existing one. This allows us (maintainers) to discuss the contribution before it is produced and avoids back and forth in reviews or stalled pull requests.
### Step 1: Generate base classes and tests files
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`.
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`.
Others 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, add a docker image in
the `docker-compose.yml`, then use the `pytest` fixture `service_container` to automatically
start the docker and shut it down for you when you are running tests.
The fixture will not pull the image for you for each test runs, you need to pull the image on your machine (at least once) using the `pytest --pull` option.
### Step 2: New connector
Open the folder `mytype` in `toucan_connectors` for your new connector and create your classes.
```python
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:
...
def get_slice(self, ...) -> DataSlice:
...
def get_status(self) -> ConnectorStatus:
...
```
### Step 3: Register your connector, add documentation
Add your connector in `toucan_connectors/__init__.py`.
The key is what we call the `type` of the connector, which
is an id used to retrieve it when used in Toucan Toco platform.
```python
CONNECTORS_CATALOGUE = {
...,
'MyType': 'mytype.mytype_connector.MyTypeConnector',
...
}
```
Add you connector requirements to the `setup.py` in the `extras_require` dictionary:
```ini
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.
You can now generate and edit the documentation page for your connector:
```shell
# Example: PYTHONPATH=. python doc/generate.py github > doc/connectors/github.md
PYTHONPATH=. python doc/generate.py myconnectormodule > doc/connectors/mytypeconnector.md
```
### Step 4 : Create a pull request
Make sure your new code is properly formatted by running `make lint`. If it's not, please use `make format`. You can now create a pull request.
## Publishing a release
1. Create a pull request updating **only** the [changelog](CHANGELOG.md) and the `version`
attribute of the `[tool.poetry]` section in the `pyproject.toml` file.
2. Once the pull request is approved, merge it using the **squash and merge** strategy.
3. Create an annotated tag for the release commit. it should be in the `vX.Y.Z` format, where `X.Y.Z` is the semver
version defined in `pyproject.toml`. Example:
```
git tag -a v1.23.45 -m v1.23.45 ea3768a
git push origin v1.23.45
```
4. In the project's *Releases* page, click on the *Draft a new release* button. Pick the tag you just pushed,
and click on *Generate release notes*. Adapt the releases notes if needed, and click on *Publish release*.
5. A GitHub action in charge of publishing the required artifacts to PyPI should now be running. Make sure
the action is successful.
%package -n python3-toucan-connectors
Summary: Toucan Toco Connectors
Provides: python-toucan-connectors
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-toucan-connectors
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://github.com/ToucanToco/toucan-connectors/actions?query=workflow%3ACI)
[](https://sonarcloud.io/dashboard?id=ToucanToco_toucan-connectors)
# Toucan Connectors
[Toucan Toco](https://toucantoco.com/fr/) data connectors are plugins to the Toucan Toco platform. Their role is to return [Pandas DataFrames](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) from many different sources.

Each connector is dedicated to a single type of source (PostrgeSQL, Mongo, Salesforce, etc...) and is made of two classes:
- `Connector` which contains all the necessary information to *use a data provider* (e.g. hostname, auth method and details, etc...).
- `DataSource` which contains all the information to *get a dataframe* (query, path, etc...) using the `Connector` class above.
The Toucan Toco platform instantiates these classes using values provided by Toucan admin and app designers, it then uses the following methods to get data and metadata:
- `Connector._retrieve_data` returning an instance of `pandas.DataFrame`, method used to return data to a Toucan Toco end user
- `Connector.get_slice` returning an instance of `DataSlice`, method used to return data to a Toucan Toco application designer when building a query.
- `Connector.get_status` returning an instance of `ConnectorStatus`, method used to inform an admin or Toucan Toco application designer of the status of its connection to a third party data service. Is it reachable from our servers? Are the authentication details and method working? etc...
## Installing for development
We use `poetry` for packaging and development. Use the following command to install the project for development:
```
poetry install -E all
```
## Dependencies
This project uses `make` and `Python 3.8`. Install the main dependencies :
```bash
pip install -e .
```
We are using the `setuptools` construct `extra_requires` to define each connector's dependencies separately. For example to install the MySQL connector dependencies:
```bash
pip install -e ".[mysql]"
```
There is a shortcut called `all` to install all the dependencies for all the connectors. I do not recommend that you use this as a contributor to this package, but if you do, use the section below to install the necessary system packages.
```bash
pip install -e ".[all]"
```
You may face issues when instally the repo locally due to dependencies.
That's why a dev container is available to be used with visual studio.
Refer to [this doc](https://code.visualstudio.com/docs/remote/containers) to use it.
### System packages
Some connectors dependencies require specific system packages. As each connector can define its dependencies separatly you do not need this until you want to use these specific connectors.
#### ODBC
On `linux`, you're going to need bindings for `unixodbc` to install `pyodbc` from the requirements, and to install that (using apt), just follow:
```bash
sudo apt-get update
sudo apt-get install unixodbc-dev
```
#### MSSSQL
To test and use `mssql` (and `azure_mssql`) you need to install the Microsoft ODBC driver for SQL Server for
[Linux](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15)
or [MacOS](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15)
#### PostgreSQL
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
We are using `pytest` and various packages of its ecosystem.
To install the testing dependencies, run:
```bash
pip install -r requirements-testing.txt
```
As each connector is an independant plugin, its tests are written independently from the rest of the codebase.
Run the tests for a specifc connector (`http_api` in this example) like this:
```bash
pytest tests/http_api
```
Note: running the tests above implies that you have installed the specific dependencies of the `http_api` connector (using the `pip install -e .[http_api]` command)
Our CI does run all the tests for all the connectors, like this:
```
pip install -e ".[all]"
make test
```
Some connectors are tested using mocks (cf. `trello`), others are tested by making calls to data providers (cf. `elasticsearch`) running on the system in docker containers. The required images are in the `tests/docker-compose.yml` file, they need to be pulled (cf. `pytest --pull`) to run the relevant tests.
## Contributing
This is an open source repository under the [BSD 3-Clause Licence](https://github.com/ToucanToco/toucan-connectors/blob/master/LICENSE). The Toucan Toco tech team are the maintainers of this repository, we welcome contributions.
At the moment the main use of this code is its integration into Toucan Toco commercially licenced software, as a result our dev and maintenance efforts applied here are mostly driven by Toucan Toco internal priorities.
The starting point of a contribution should be an [Issue](https://github.com/ToucanToco/toucan-connectors/issues), either one you create or an existing one. This allows us (maintainers) to discuss the contribution before it is produced and avoids back and forth in reviews or stalled pull requests.
### Step 1: Generate base classes and tests files
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`.
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`.
Others 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, add a docker image in
the `docker-compose.yml`, then use the `pytest` fixture `service_container` to automatically
start the docker and shut it down for you when you are running tests.
The fixture will not pull the image for you for each test runs, you need to pull the image on your machine (at least once) using the `pytest --pull` option.
### Step 2: New connector
Open the folder `mytype` in `toucan_connectors` for your new connector and create your classes.
```python
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:
...
def get_slice(self, ...) -> DataSlice:
...
def get_status(self) -> ConnectorStatus:
...
```
### Step 3: Register your connector, add documentation
Add your connector in `toucan_connectors/__init__.py`.
The key is what we call the `type` of the connector, which
is an id used to retrieve it when used in Toucan Toco platform.
```python
CONNECTORS_CATALOGUE = {
...,
'MyType': 'mytype.mytype_connector.MyTypeConnector',
...
}
```
Add you connector requirements to the `setup.py` in the `extras_require` dictionary:
```ini
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.
You can now generate and edit the documentation page for your connector:
```shell
# Example: PYTHONPATH=. python doc/generate.py github > doc/connectors/github.md
PYTHONPATH=. python doc/generate.py myconnectormodule > doc/connectors/mytypeconnector.md
```
### Step 4 : Create a pull request
Make sure your new code is properly formatted by running `make lint`. If it's not, please use `make format`. You can now create a pull request.
## Publishing a release
1. Create a pull request updating **only** the [changelog](CHANGELOG.md) and the `version`
attribute of the `[tool.poetry]` section in the `pyproject.toml` file.
2. Once the pull request is approved, merge it using the **squash and merge** strategy.
3. Create an annotated tag for the release commit. it should be in the `vX.Y.Z` format, where `X.Y.Z` is the semver
version defined in `pyproject.toml`. Example:
```
git tag -a v1.23.45 -m v1.23.45 ea3768a
git push origin v1.23.45
```
4. In the project's *Releases* page, click on the *Draft a new release* button. Pick the tag you just pushed,
and click on *Generate release notes*. Adapt the releases notes if needed, and click on *Publish release*.
5. A GitHub action in charge of publishing the required artifacts to PyPI should now be running. Make sure
the action is successful.
%package help
Summary: Development documents and examples for toucan-connectors
Provides: python3-toucan-connectors-doc
%description help
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://pypi.python.org/pypi/toucan-connectors)
[](https://github.com/ToucanToco/toucan-connectors/actions?query=workflow%3ACI)
[](https://sonarcloud.io/dashboard?id=ToucanToco_toucan-connectors)
# Toucan Connectors
[Toucan Toco](https://toucantoco.com/fr/) data connectors are plugins to the Toucan Toco platform. Their role is to return [Pandas DataFrames](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) from many different sources.

Each connector is dedicated to a single type of source (PostrgeSQL, Mongo, Salesforce, etc...) and is made of two classes:
- `Connector` which contains all the necessary information to *use a data provider* (e.g. hostname, auth method and details, etc...).
- `DataSource` which contains all the information to *get a dataframe* (query, path, etc...) using the `Connector` class above.
The Toucan Toco platform instantiates these classes using values provided by Toucan admin and app designers, it then uses the following methods to get data and metadata:
- `Connector._retrieve_data` returning an instance of `pandas.DataFrame`, method used to return data to a Toucan Toco end user
- `Connector.get_slice` returning an instance of `DataSlice`, method used to return data to a Toucan Toco application designer when building a query.
- `Connector.get_status` returning an instance of `ConnectorStatus`, method used to inform an admin or Toucan Toco application designer of the status of its connection to a third party data service. Is it reachable from our servers? Are the authentication details and method working? etc...
## Installing for development
We use `poetry` for packaging and development. Use the following command to install the project for development:
```
poetry install -E all
```
## Dependencies
This project uses `make` and `Python 3.8`. Install the main dependencies :
```bash
pip install -e .
```
We are using the `setuptools` construct `extra_requires` to define each connector's dependencies separately. For example to install the MySQL connector dependencies:
```bash
pip install -e ".[mysql]"
```
There is a shortcut called `all` to install all the dependencies for all the connectors. I do not recommend that you use this as a contributor to this package, but if you do, use the section below to install the necessary system packages.
```bash
pip install -e ".[all]"
```
You may face issues when instally the repo locally due to dependencies.
That's why a dev container is available to be used with visual studio.
Refer to [this doc](https://code.visualstudio.com/docs/remote/containers) to use it.
### System packages
Some connectors dependencies require specific system packages. As each connector can define its dependencies separatly you do not need this until you want to use these specific connectors.
#### ODBC
On `linux`, you're going to need bindings for `unixodbc` to install `pyodbc` from the requirements, and to install that (using apt), just follow:
```bash
sudo apt-get update
sudo apt-get install unixodbc-dev
```
#### MSSSQL
To test and use `mssql` (and `azure_mssql`) you need to install the Microsoft ODBC driver for SQL Server for
[Linux](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15)
or [MacOS](https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15)
#### PostgreSQL
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
We are using `pytest` and various packages of its ecosystem.
To install the testing dependencies, run:
```bash
pip install -r requirements-testing.txt
```
As each connector is an independant plugin, its tests are written independently from the rest of the codebase.
Run the tests for a specifc connector (`http_api` in this example) like this:
```bash
pytest tests/http_api
```
Note: running the tests above implies that you have installed the specific dependencies of the `http_api` connector (using the `pip install -e .[http_api]` command)
Our CI does run all the tests for all the connectors, like this:
```
pip install -e ".[all]"
make test
```
Some connectors are tested using mocks (cf. `trello`), others are tested by making calls to data providers (cf. `elasticsearch`) running on the system in docker containers. The required images are in the `tests/docker-compose.yml` file, they need to be pulled (cf. `pytest --pull`) to run the relevant tests.
## Contributing
This is an open source repository under the [BSD 3-Clause Licence](https://github.com/ToucanToco/toucan-connectors/blob/master/LICENSE). The Toucan Toco tech team are the maintainers of this repository, we welcome contributions.
At the moment the main use of this code is its integration into Toucan Toco commercially licenced software, as a result our dev and maintenance efforts applied here are mostly driven by Toucan Toco internal priorities.
The starting point of a contribution should be an [Issue](https://github.com/ToucanToco/toucan-connectors/issues), either one you create or an existing one. This allows us (maintainers) to discuss the contribution before it is produced and avoids back and forth in reviews or stalled pull requests.
### Step 1: Generate base classes and tests files
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`.
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`.
Others 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, add a docker image in
the `docker-compose.yml`, then use the `pytest` fixture `service_container` to automatically
start the docker and shut it down for you when you are running tests.
The fixture will not pull the image for you for each test runs, you need to pull the image on your machine (at least once) using the `pytest --pull` option.
### Step 2: New connector
Open the folder `mytype` in `toucan_connectors` for your new connector and create your classes.
```python
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:
...
def get_slice(self, ...) -> DataSlice:
...
def get_status(self) -> ConnectorStatus:
...
```
### Step 3: Register your connector, add documentation
Add your connector in `toucan_connectors/__init__.py`.
The key is what we call the `type` of the connector, which
is an id used to retrieve it when used in Toucan Toco platform.
```python
CONNECTORS_CATALOGUE = {
...,
'MyType': 'mytype.mytype_connector.MyTypeConnector',
...
}
```
Add you connector requirements to the `setup.py` in the `extras_require` dictionary:
```ini
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.
You can now generate and edit the documentation page for your connector:
```shell
# Example: PYTHONPATH=. python doc/generate.py github > doc/connectors/github.md
PYTHONPATH=. python doc/generate.py myconnectormodule > doc/connectors/mytypeconnector.md
```
### Step 4 : Create a pull request
Make sure your new code is properly formatted by running `make lint`. If it's not, please use `make format`. You can now create a pull request.
## Publishing a release
1. Create a pull request updating **only** the [changelog](CHANGELOG.md) and the `version`
attribute of the `[tool.poetry]` section in the `pyproject.toml` file.
2. Once the pull request is approved, merge it using the **squash and merge** strategy.
3. Create an annotated tag for the release commit. it should be in the `vX.Y.Z` format, where `X.Y.Z` is the semver
version defined in `pyproject.toml`. Example:
```
git tag -a v1.23.45 -m v1.23.45 ea3768a
git push origin v1.23.45
```
4. In the project's *Releases* page, click on the *Draft a new release* button. Pick the tag you just pushed,
and click on *Generate release notes*. Adapt the releases notes if needed, and click on *Publish release*.
5. A GitHub action in charge of publishing the required artifacts to PyPI should now be running. Make sure
the action is successful.
%prep
%autosetup -n toucan-connectors-4.4.1
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-toucan-connectors -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Wed Apr 12 2023 Python_Bot <Python_Bot@openeuler.org> - 4.4.1-1
- Package Spec generated
|