Skip to content

Commit 8e9eaa8

Browse files
btkcodedevmarcosmarxmoctavia-squidington-iii
authored
🎉 New Source: Punk API [low-code cdk] (#18724)
* New source: punkapi * chore: Added docs, fix: Streams, Test: Pass * chore: Add doc URL * All comments resolved * Resolve Merge conflicts * Resolve Merge conflicts * feat: Added paginator, Introduced request params * feat: fixed paginator * add punk api to source def * update sample file * rebase * auto-bump connector version Co-authored-by: btkcodedev <[email protected]> Co-authored-by: marcosmarxm <[email protected]> Co-authored-by: Octavia Squidington III <[email protected]>
1 parent 9d03921 commit 8e9eaa8

File tree

25 files changed

+1301
-0
lines changed

25 files changed

+1301
-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
@@ -1213,6 +1213,13 @@
12131213
documentationUrl: https://docs.airbyte.com/integrations/sources/public-apis
12141214
sourceType: api
12151215
releaseStage: alpha
1216+
- name: Punk API
1217+
sourceDefinitionId: dbe9b7ae-7b46-4e44-a507-02a343cf7230
1218+
dockerRepository: airbyte/source-punk-api
1219+
dockerImageTag: 0.1.0
1220+
documentationUrl: https://docs.airbyte.com/integrations/sources/punk-api
1221+
sourceType: api
1222+
releaseStage: alpha
12161223
- name: PyPI
12171224
sourceDefinitionId: 88ecd3a8-5f5b-11ed-9b6a-0242ac120002
12181225
dockerRepository: airbyte/source-pypi

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11360,6 +11360,42 @@
1136011360
supportsNormalization: false
1136111361
supportsDBT: false
1136211362
supported_destination_sync_modes: []
11363+
- dockerImage: "airbyte/source-punk-api:0.1.0"
11364+
spec:
11365+
documentationUrl: "https://docs.airbyte.com/integrations/sources/punk-api"
11366+
connectionSpecification:
11367+
$schema: "http://json-schema.org/draft-07/schema#"
11368+
title: "Punk Api Spec"
11369+
type: "object"
11370+
required:
11371+
- "brewed_before"
11372+
- "brewed_after"
11373+
additionalProperties: true
11374+
properties:
11375+
id:
11376+
title: "Beers with specific ID"
11377+
type: "string"
11378+
description: "To extract specific data with Unique ID"
11379+
examples:
11380+
- 1
11381+
- 22
11382+
brewed_before:
11383+
title: "Brewed before data to get incremental reads"
11384+
type: "string"
11385+
description: "To extract specific data with Unique ID"
11386+
pattern: "^[0-9]{2}-[0-9]{4}$"
11387+
examples:
11388+
- "MM-YYYY"
11389+
brewed_after:
11390+
title: "Brewed after data to get incremental reads"
11391+
type: "string"
11392+
description: "To extract specific data with Unique ID"
11393+
pattern: "^[0-9]{2}-[0-9]{4}$"
11394+
examples:
11395+
- "MM-YYYY"
11396+
supportsNormalization: false
11397+
supportsDBT: false
11398+
supported_destination_sync_modes: []
1136311399
- dockerImage: "airbyte/source-pypi:0.1.0"
1136411400
spec:
1136511401
documentationUrl: "https://docs.airbyte.io/integrations/sources/pypi"
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_punk_api
5+
!setup.py
6+
!secrets
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
13+
COPY setup.py ./
14+
# install necessary packages to a temporary folder
15+
RUN pip install --prefix=/install .
16+
17+
# build a clean environment
18+
FROM base
19+
WORKDIR /airbyte/integration_code
20+
21+
# copy all loaded and built libraries to a pure basic image
22+
COPY --from=builder /install /usr/local
23+
# add default timezone settings
24+
COPY --from=builder /usr/share/zoneinfo/Etc/UTC /etc/localtime
25+
RUN echo "Etc/UTC" > /etc/timezone
26+
27+
# bash is installed for more convenient debugging.
28+
RUN apk --no-cache add bash
29+
30+
# copy payload code only
31+
COPY main.py ./
32+
COPY source_punk_api ./source_punk_api
33+
34+
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
35+
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
36+
37+
LABEL io.airbyte.version=0.1.0
38+
LABEL io.airbyte.name=airbyte/source-punk-api
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Punk Api Source
2+
3+
This is the repository for the Punk Api configuration based source connector.
4+
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.io/integrations/sources/punk-api).
5+
6+
## Local development
7+
8+
### Prerequisites
9+
**To iterate on this connector, make sure to complete this prerequisites section.**
10+
11+
#### Minimum Python version required `= 3.9.0`
12+
13+
#### Build & Activate Virtual Environment and install dependencies
14+
From this connector directory, create a virtual environment:
15+
```
16+
python -m venv .venv
17+
```
18+
19+
This will generate a virtualenv for this module in `.venv/`. Make sure this venv is active in your
20+
development environment of choice. To activate it from the terminal, run:
21+
```
22+
source .venv/bin/activate
23+
pip install -r requirements.txt
24+
```
25+
If you are in an IDE, follow your IDE's instructions to activate the virtualenv.
26+
27+
Note that while we are installing dependencies from `requirements.txt`, you should only edit `setup.py` for your dependencies. `requirements.txt` is
28+
used for editable installs (`pip install -e`) to pull in Python dependencies from the monorepo and will call `setup.py`.
29+
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
30+
should work as you expect.
31+
#### Building via Gradle
32+
You can also build the connector in Gradle. This is typically used in CI and not needed for your development workflow.
33+
34+
To build using Gradle, from the Airbyte repository root, run:
35+
```
36+
./gradlew :airbyte-integrations:connectors:source-punk-api:build
37+
```
38+
39+
#### Create credentials
40+
**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.io/integrations/sources/punk-api)
41+
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_punk_api/spec.yaml` file.
42+
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
43+
See `integration_tests/sample_config.json` for a sample config file.
44+
45+
**If you are an Airbyte core member**, copy the credentials in Lastpass under the secret name `source punk-api test creds`
46+
and place them into `secrets/config.json`.
47+
48+
### Locally running the connector docker image
49+
50+
#### Build
51+
First, make sure you build the latest Docker image:
52+
```
53+
docker build . -t airbyte/source-punk-api:dev
54+
```
55+
56+
You can also build the connector image via Gradle:
57+
```
58+
./gradlew :airbyte-integrations:connectors:source-punk-api:airbyteDocker
59+
```
60+
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
61+
the Dockerfile.
62+
63+
#### Run
64+
Then run any of the connector commands as follows:
65+
```
66+
docker run --rm airbyte/source-punk-api:dev spec
67+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-punk-api:dev check --config /secrets/config.json
68+
docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-punk-api:dev discover --config /secrets/config.json
69+
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-punk-api:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
70+
```
71+
## Testing
72+
73+
#### Acceptance Tests
74+
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.
75+
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.
76+
77+
To run your integration tests with docker
78+
79+
### Using gradle to run tests
80+
All commands should be run from airbyte project root.
81+
To run unit tests:
82+
```
83+
./gradlew :airbyte-integrations:connectors:source-punk-api:unitTest
84+
```
85+
To run acceptance and custom integration tests:
86+
```
87+
./gradlew :airbyte-integrations:connectors:source-punk-api:integrationTest
88+
```
89+
90+
## Dependency Management
91+
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.
92+
We split dependencies between two groups, dependencies that are:
93+
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
94+
* required for the testing need to go to `TEST_REQUIREMENTS` list
95+
96+
### Publishing a new version of the connector
97+
You've checked out the repo, implemented a million dollar feature, and you're ready to share your changes with the world. Now what?
98+
1. Make sure your changes are passing unit and integration tests.
99+
1. Bump the connector version in `Dockerfile` -- just increment the value of the `LABEL io.airbyte.version` appropriately (we use [SemVer](https://semver.org/)).
100+
1. Create a Pull Request.
101+
1. Pat yourself on the back for being an awesome contributor.
102+
1. Someone from Airbyte will take a look at your PR and iterate with you to merge it into master.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#
2+
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
3+
#
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
connector_image: airbyte/source-punk-api:dev
3+
acceptance_tests:
4+
spec:
5+
tests:
6+
- spec_path: "source_punk_api/spec.yaml"
7+
connection:
8+
tests:
9+
- config_path: "secrets/config.json"
10+
status: "succeed"
11+
- config_path: "integration_tests/invalid_config.json"
12+
status: "failed"
13+
discovery:
14+
tests:
15+
- config_path: "secrets/config.json"
16+
basic_read:
17+
tests:
18+
- config_path: "secrets/config.json"
19+
configured_catalog_path: "integration_tests/configured_catalog.json"
20+
empty_streams: []
21+
full_refresh:
22+
tests:
23+
- config_path: "secrets/config.json"
24+
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Punk-API
2+
3+
The connector uses the v2 API documented here: https://punkapi.com/documentation/v2 . It is
4+
straightforward HTTP REST API with API authentication.
5+
6+
## API key
7+
8+
Api key is not required for this connector to work,But a dummy key need to be passed to enhance in next versions. Example:123
9+
Just pass the dummy API key and optional parameter for establishing the connection. Example:123
10+
11+
## Implementation details
12+
13+
## Setup guide
14+
15+
### Step 1: Set up Punk-API connection
16+
17+
- Pass a dummy API key (Example: 12345)
18+
- Params (Optional ID)
19+
20+
## Step 2: Generate schema for the endpoint
21+
22+
### Custom schema is generated and tested with different IDs
23+
24+
## Step 3: Spec, Secrets, and connector yaml files are configured with reference to the Airbyte documentation.
25+
26+
## In a nutshell:
27+
28+
1. Navigate to the Airbyte Open Source dashboard.
29+
2. Set the name for your source.
30+
4. Enter your dummy `api_key`.
31+
5. Enter the params configuration if needed: ID (Optional)
32+
6. Click **Set up source**.
33+
34+
* We use only GET methods, towards the beers endpoints which is straightforward
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_punk_api'
9+
}

0 commit comments

Comments
 (0)