Skip to content

Commit d6d52c5

Browse files
Zawar92marcosmarxmoctavia-squidington-iii
authored
🎉 New Source: RKI (Robert Koch-Institut) Covid Public API (#11732)
* Added source for RKI-covid-germany, updated spec.json, implemented source with check and discover method added germany.json. * implemented incremental method for germany history cases with date as parameters, updated streams, added cursor field for incremental streams. * main file added. * added Incidence source with date as parameter. Incremental stream. spec, source, schemas updated, added class GermanHistoryIncidence added. * Added a full-refresh stream for germany/age-group .Added incremental streams for deaths/:days, recovered/:days, frozen-incidence/:days, hospitalization/:days. Updated source.py methods. Updated sepc.json properties key. Updated configured_catalogue.json with required streams. Updated config.json * writting test unit test cases for incremental streams: german history cases and german history incidence. * Incremental streams for germanhistorydeaths, germanhistoryfrozenIncidence, germanhistoryhospitalization, germanhistoryrecovered. Fixing other test cases. * Added test stream for age group and germany. * changes in Readme and source.py. * IncrementalMixin added to class GermanyHistoryCases. AFter review IncrementalMixin will be implemented to all incremental classes. * Implemented Incremental mixin or GermanHistory Cases connector. * corrected changes. * adding integration test * comment acceptence test. * On path with master * updated the changes for PR request. * changed file source-rki-covid/integration_tests/configured_catalog.json * corrected flake and blackformatting. Build gradel. * Worked on the suggestions. * source_rki_covid/schemas/germany_age_groups.json * uodated abnormal_state.json * updated the schemas for german age groups and history hospitalization. * correct dockerfile and update airbyte_cdk version * run format * update python version * correct dockerfile build * add source in seed * update uuid for rki-covid source * change docker * add bash * auto-bump connector version * run seed file * correct doc * auto-bump connector version Co-authored-by: Marcos Marx Millnitz <[email protected]> Co-authored-by: Octavia Squidington III <[email protected]>
1 parent ad1fd2b commit d6d52c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2144
-0
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,13 @@
776776
icon: retently.svg
777777
sourceType: api
778778
releaseStage: alpha
779+
- name: RKI Covid
780+
sourceDefinitionId: d78e5de0-aa44-4744-aa4f-74c818ccfe19
781+
dockerRepository: airbyte/source-rki-covid
782+
dockerImageTag: 0.1.1
783+
documentationUrl: https://docs.airbyte.io/integrations/sources/rki-covid
784+
sourceType: api
785+
releaseStage: alpha
779786
- name: S3
780787
sourceDefinitionId: 69589781-7828-43c5-9f63-8925b1c1ccc2
781788
dockerRepository: airbyte/source-s3

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7218,6 +7218,26 @@
72187218
path_in_connector_config:
72197219
- "credentials"
72207220
- "client_secret"
7221+
- dockerImage: "airbyte/source-rki-covid:0.1.1"
7222+
spec:
7223+
documentationUrl: "https://docs.airbyte.com/integrations/sources/rki-covid"
7224+
connectionSpecification:
7225+
$schema: "http://json-schema.org/draft-07/schema#"
7226+
title: "RKI Covid Spec"
7227+
type: "object"
7228+
required:
7229+
- "start_date"
7230+
additionalProperties: false
7231+
properties:
7232+
start_date:
7233+
type: "string"
7234+
title: "Start Date"
7235+
description: "UTC date in the format 2017-01-25. Any data before this date\
7236+
\ will not be replicated."
7237+
order: 1
7238+
supportsNormalization: false
7239+
supportsDBT: false
7240+
supported_destination_sync_modes: []
72217241
- dockerImage: "airbyte/source-s3:0.1.14"
72227242
spec:
72237243
documentationUrl: "https://docs.airbyte.io/integrations/sources/s3"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*
2+
!Dockerfile
3+
!main.py
4+
!source_rki_covid
5+
!setup.py
6+
!secrets
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM python:3.9.11-alpine3.15 as base
2+
3+
# build and load all requirements
4+
FROM base as builder
5+
WORKDIR /airbyte/integration_code
6+
7+
# upgrade pip to the latest version
8+
RUN apk --no-cache upgrade \
9+
&& pip install --upgrade pip \
10+
&& apk --no-cache add tzdata build-base
11+
12+
COPY setup.py ./
13+
# install necessary packages to a temporary folder
14+
RUN pip install --prefix=/install .
15+
16+
# build a clean environment
17+
FROM base
18+
WORKDIR /airbyte/integration_code
19+
20+
# copy all loaded and built libraries to a pure basic image
21+
COPY --from=builder /install /usr/local
22+
# add default timezone settings
23+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
24+
RUN echo "Etc/UTC" > /etc/timezone
25+
26+
# copy payload code only
27+
COPY main.py ./
28+
COPY source_rki_covid ./source_rki_covid
29+
30+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
31+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
32+
33+
LABEL io.airbyte.version=0.1.1
34+
LABEL io.airbyte.name=airbyte/source-rki-covid
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# RKI Covid Source
2+
3+
This is the repository for the RkI (Robert Koch-Institut - von Marlon Lückert) Covid-19 source connector, written in Python.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/rki-covid).
5+
6+
## Local development
7+
### Developed Streams (Endpoints)
8+
```
9+
Germany:
10+
1. /germany
11+
2. /germany/age-groups
12+
3. /germany/history/cases/:days
13+
4. /germany/history/incidence/:days
14+
5. /germany/history/deaths/:days
15+
6. /germany/history/recovered/:days
16+
7. /germany/history/frozen-incidence/:days
17+
8. /germany/history/hospitalization/:days
18+
```
19+
20+
### Prerequisites
21+
**To iterate on this connector, make sure to complete this prerequisites section.**
22+
23+
#### Minimum Python version required `= 3.7.0`
24+
25+
#### Build & Activate Virtual Environment and install dependencies
26+
From this connector directory, create a virtual environment:
27+
```
28+
python -m venv .venv
29+
```
30+
31+
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
32+
development environment of choice. To activate it from the terminal, run:
33+
```
34+
source .venv/bin/activate
35+
pip install -r requirements.txt
36+
pip install '.[tests]'
37+
```
38+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
39+
40+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
41+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
42+
If this is mumbo jumbo to you, don't worry about it, just put your deps in `setup.py` but install using `pip install -r requirements.txt` and everything
43+
should work as you expect.
44+
45+
#### Building via Gradle
46+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
47+
48+
To build using Gradle, from the Airbyte repository root, run:
49+
```
50+
./gradlew :airbyte-integrations:connectors:source-rki-covid:build
51+
```
52+
53+
#### Create credentials
54+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/rki-covid)
55+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_rki_covid/spec.json` file.
56+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
57+
See `integration_tests/sample_config.json` for a sample config file.
58+
59+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source rki-covid test creds`
60+
and place them into `secrets/config.json`.
61+
62+
### Locally running the connector
63+
```
64+
python main.py spec
65+
python main.py check --config secrets/config.json
66+
python main.py discover --config secrets/config.json
67+
python main.py read --config secrets/config.json --catalog integration_tests/configured_catalog.json
68+
```
69+
70+
### Locally running the connector docker image
71+
72+
#### Build
73+
First, make sure you build the latest Docker image:
74+
```
75+
docker build . -t airbyte/source-rki-covid:dev
76+
```
77+
78+
You can also build the connector image via Gradle:
79+
```
80+
./gradlew :airbyte-integrations:connectors:source-rki-covid:airbyteDocker
81+
```
82+
When building via Gradle, the docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in
83+
the Dockerfile.
84+
85+
#### Run
86+
Then run any of the connector commands as follows:
87+
```
88+
docker run --rm airbyte/source-rki-covid:dev spec
89+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-rki-covid:dev check --config /secrets/config.json
90+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-rki-covid:dev discover --config /secrets/config.json
91+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-rki-covid:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
92+
```
93+
## Testing
94+
Make sure to familiarize yourself with [pytest test discovery](https://docs.pytest.org/en/latest/goodpractices.html#test-discovery) to know how your test files and methods should be named.
95+
First install test dependencies into your virtual environment:
96+
```
97+
pip install .[tests]
98+
```
99+
### Unit Tests
100+
To run unit tests locally, from the connector directory run:
101+
```
102+
python -m pytest unit_tests
103+
```
104+
105+
### Integration Tests
106+
There are two types of integration tests: Acceptance Tests (Airbyte's test suite for all source connectors) and custom integration tests (which are specific to this connector).
107+
#### Custom Integration tests
108+
Place custom tests inside `integration_tests/` folder, then, from the connector root, run
109+
```
110+
python -m pytest integration_tests
111+
```
112+
#### Acceptance Tests
113+
Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) for more information.
114+
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
115+
To run your integration tests with acceptance tests, from the connector root, run
116+
```
117+
python -m pytest integration_tests -p integration_tests.acceptance
118+
```
119+
To run your integration tests with docker
120+
121+
### Using gradle to run tests
122+
All commands should be run from airbyte project root.
123+
To run unit tests:
124+
```
125+
./gradlew :airbyte-integrations:connectors:source-rki-covid:unitTest
126+
```
127+
To run acceptance and custom integration tests:
128+
```
129+
./gradlew :airbyte-integrations:connectors:source-rki-covid:integrationTest
130+
```
131+
132+
## Dependency Management
133+
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
134+
We split dependencies between two groups, dependencies that are:
135+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
136+
* required for the testing need to go to `TEST_REQUIREMENTS` list
137+
138+
### Publishing a new version of the connector
139+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
140+
1. Make sure your changes are passing unit and integration tests.
141+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
142+
1. Create a Pull Request.
143+
1. Pat yourself on the back for being an awesome contributor.
144+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference)
2+
# for more information about how to configure these tests
3+
connector_image: airbyte/source-rki-covid:dev
4+
tests:
5+
spec:
6+
- spec_path: "source_rki_covid/spec.json"
7+
connection:
8+
- config_path: "secrets/config.json"
9+
status: "succeed"
10+
discovery:
11+
- config_path: "secrets/config.json"
12+
basic_read:
13+
- config_path: "secrets/config.json"
14+
configured_catalog_path: "integration_tests/configured_catalog.json"
15+
empty_streams: [ "germany", "germany_age_groups", "german_history_frozen_incidence"]
16+
# TODO uncomment this block to specify that the tests should assert the connector outputs the records provided in the input file a file
17+
# expect_records:
18+
# path: "integration_tests/expected_records.txt"
19+
# extra_fields: no
20+
# exact_order: no
21+
# extra_records: yes
22+
incremental: # TODO
23+
- config_path: "secrets/config.json"
24+
configured_catalog_path: "integration_tests/configured_catalog.json"
25+
future_state_path: "integration_tests/abnormal_state.json"
26+
full_refresh:
27+
- config_path: "secrets/config.json"
28+
configured_catalog_path: "integration_tests/configured_catalog.json"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
# Build latest connector image
4+
docker build . -t $(cat acceptance-test-config.yml | grep "connector_image" | head -n 1 | cut -d: -f2-)
5+
6+
# Pull latest acctest image
7+
docker pull airbyte/source-acceptance-test:latest
8+
9+
# Run
10+
docker run --rm -it \
11+
-v /var/run/docker.sock:/var/run/docker.sock \
12+
-v /tmp:/tmp \
13+
-v $(pwd):/test_input \
14+
airbyte/source-acceptance-test \
15+
--acceptance-test-config /test_input
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The (Robert Koch-Institut - von Marlon Lückert) Covid-19 is [a REST based API](https://api.corona-zahlen.org/).
2+
Connector is implemented with [Airbyte CDK](https://docs.airbyte.io/connector-development/cdk-python).
3+
4+
## Cases In Germany Covid api stream
5+
The basic entry stream is 'germany'. All other streams are extended version of base stream and passing parameters also result in sliced data.
6+
For production, every developer application can view multiple streams.
7+
8+
## Endpoints
9+
* [Provides covid cases and other information in Germany.](https://api.corona-zahlen.org/germany) \(Non-Incremental\ Entry-Stream)
10+
* [Provides covid cases and other information in Germany, group by age.](https://api.corona-zahlen.org/germany/age-groups) \(Non-Incremental\)
11+
* [Provides cases in Germany based on days.](https://api.corona-zahlen.org/germany/germany/history/cases/:days) \(Incremental\)
12+
* [Provides incidence rate of covid in Germany based on days.](https://api.corona-zahlen.org/germany/germany/history/incidence/:days) \(Incremental\)
13+
* [Provides death rate in Germany over days](https://api.corona-zahlen.org/germany/germany/history/deaths/:days) \(Incremental\)
14+
* [Provides recovery rate in Germany over days.](https://api.corona-zahlen.org/germany/germany/history/recovered/:days) \(Incremental\)
15+
* [Provides frozen incidence in Germany over days.](https://api.corona-zahlen.org/germany/germany/history/frozen-incidence/:days) \(Incremental\)
16+
* [Provides hospitalization rate in Germany over days.](https://api.corona-zahlen.org/germany/germany/history/hospitalization/:days) \(Incremental\)
17+
18+
19+
20+
Incremental streams have required parameter start-date. Without passing start-date as parameter full-refresh occurs.
21+
As cursor field this connector uses "date".
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
plugins {
2+
id 'airbyte-python'
3+
id 'airbyte-docker'
4+
id 'airbyte-source-acceptance-test'
5+
}
6+
7+
airbytePython {
8+
moduleDirectory 'source_rki_covid'
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"germany_history_cases": {
3+
"date": "2024-04-06T00:00:00.000Z"
4+
},
5+
"german_history_incidence": {
6+
"date": "2024-04-06T00:00:00.000Z"
7+
},
8+
"german_history_deaths": {
9+
"date": "2024-04-06T00:00:00.000Z"
10+
},
11+
"german_history_recovered": {
12+
"date": "2024-04-06T00:00:00.000Z"
13+
},
14+
"german_history_hospitalization": {
15+
"date": "2024-04-07T00:00:00.000Z"
16+
},
17+
"german_history_frozen_incidence": {
18+
"date": "2024-01-01T00:00:00.000Z"
19+
}
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
4+
5+
6+
import pytest
7+
8+
pytest_plugins = ("source_acceptance_test.plugin",)
9+
10+
11+
@pytest.fixture(scope="session", autouse=True)
12+
def connector_setup():
13+
"""This fixture is a placeholder for external resources that acceptance test might require."""
14+
yield

0 commit comments

Comments
 (0)