Custom Sources
A custom source is a Python file, source.py, that subclasses bizon’s AbstractSource. The platform keeps each one in its own directory under CUSTOM_SOURCES_DIR:
custom_sources/├── jsonplaceholder/│ └── source.py└── my_api/ └── source.pyDocker Compose and the Helm chart mount this directory at /custom_sources in the API and worker containers.
Bundled sources
Section titled “Bundled sources”The repository ships these sources in custom_sources/: buildbetter, hubspot, jsonplaceholder, metabase, noticeable, notion, periscope, pokeapi, rootly, sana_ai and spotdraft. jsonplaceholder and pokeapi need no credentials and are good templates.
Write a source
Section titled “Write a source”from typing import List, Tuple
from bizon.source.config import SourceConfigfrom bizon.source.models import SourceIteration, SourceRecordfrom bizon.source.source import AbstractSourcefrom requests.auth import AuthBase
class MyApiConfig(SourceConfig): api_key: str
class MyApiSource(AbstractSource): def __init__(self, config: MyApiConfig): super().__init__(config) self.config: MyApiConfig = config
@staticmethod def streams() -> List[str]: return ["users", "orders"]
@staticmethod def get_config_class() -> type: return MyApiConfig
def get_authenticator(self) -> AuthBase | None: return None
def check_connection(self) -> Tuple[bool, str | None]: response = self.session.get("https://api.example.com/health") return response.ok, None if response.ok else f"HTTP {response.status_code}"
def get_total_records_count(self) -> int | None: return None
def get(self, pagination: dict = None) -> SourceIteration: page = (pagination or {}).get("page", 1) rows = self.session.get( f"https://api.example.com/{self.config.stream}", params={"page": page}, headers={"Authorization": f"Bearer {self.config.api_key}"}, ).json() return SourceIteration( records=[SourceRecord(id=str(r["id"]), data=r) for r in rows], next_pagination={"page": page + 1} if rows else {}, # empty dict ends the stream )| Method | Required | Purpose |
|---|---|---|
streams() | yes | Static. The stream names. |
get_config_class() | yes | Static. A SourceConfig subclass with your extra fields. |
get_authenticator() | yes | A requests AuthBase, or None. It is attached to self.session. |
check_connection() | yes | Returns (ok, error_message). |
get_total_records_count() | yes | Total records if known, else None. |
get(pagination) | yes | Returns one page as a SourceIteration. Called until next_pagination is empty. |
get_records_after(source_state, pagination) | no | For incremental syncs. |
self.session is a requests session that bizon sets up for you. See Custom sources in the Bizon reference for more.
Use a source in a pipeline
Section titled “Use a source in a pipeline”Point source_file_path at the file inside the container:
{ "source": { "name": "my_api", "stream": "users", "source_file_path": "/custom_sources/my_api/source.py", "api_key": "..." }, "destination": { "name": "logger", "config": { "dummy": "dummy" } }}Fields from your config class, like api_key here, go directly under source. GET /api/connectors/custom-sources returns the file_path to use for each source. In the UI pipeline form, pick Custom Source and the path is filled in, but the form has no inputs for extra fields: add them through the API.
Upload
Section titled “Upload”On the Custom Sources page, click Upload and pick a file, or call POST /api/custom-sources/upload.
.py: becomes<file name>/source.py.My-API.pybecomesmy_api..zip: must contain asource.py. The directory is named after the zip’s top-level folder, or the zip itself. Onlysource.pyis extracted, so the source can’t import sibling modules from the zip.
The platform imports the file and checks that it defines an AbstractSource subclass with streams(). An existing name is rejected: delete the old source first.
Git sync
Section titled “Git sync”Git sync keeps CUSTOM_SOURCES_DIR in step with a folder in a Git repository, so sources go through code review instead of uploads.
| Variable | Default | Description |
|---|---|---|
GIT_SYNC_ENABLED | false | Turn on Git sync |
GIT_SYNC_REPO_URL | Repository URL, e.g. https://github.com/acme/bizon-sources.git | |
GIT_SYNC_BRANCH | main | Branch to sync |
GIT_SYNC_PATH | custom_sources | Folder in the repository that holds the sources |
GIT_SYNC_TOKEN | Access token for private HTTPS repositories | |
GIT_SYNC_WEBHOOK_SECRET | Shared secret for push webhooks |
How a sync works
Section titled “How a sync works”- The API does a shallow (depth 1), sparse fetch of
GIT_SYNC_PATHfromGIT_SYNC_BRANCH. - Every subdirectory of that folder that contains a
source.pyreplaces the directory of the same name inCUSTOM_SOURCES_DIR. - Sources deleted from the repository are not deleted locally. Remove them with the UI or
DELETE /api/custom-sources/{name}.
With an HTTPS URL, the token is inserted into the URL as https://<token>@host/.... Each Git command times out after 2 minutes.
A sync runs:
- when the API starts;
- when you click Sync from Git on the Custom Sources page (shown only when sync is enabled), or call
POST /api/custom-sources/git-sync; - when a push webhook arrives for the configured branch.
Webhooks
Section titled “Webhooks”Set GIT_SYNC_WEBHOOK_SECRET on the API, then add a webhook to the repository:
| Setting | GitHub | GitLab |
|---|---|---|
| URL | https://<host>/api/custom-sources/git-sync/webhook | same |
| Content type | application/json | (always JSON) |
| Secret | Secret = GIT_SYNC_WEBHOOK_SECRET | Secret token = GIT_SYNC_WEBHOOK_SECRET |
| Events | Just the push event | Push events |
GitHub requests are verified with the X-Hub-Signature-256 HMAC, GitLab requests with X-Gitlab-Token. Pushes to other branches are ignored. The sync runs in the background after the webhook returns.
Generate a secret with:
python -c "import secrets; print(secrets.token_hex(32))"The webhook is exempt from ADMIN_PASSWORD. It authenticates with the secret alone.
Test a connection in the UI
Section titled “Test a connection in the UI”Each source card on the Custom Sources page has View Code, Test and Delete.
Test opens a form generated from the source’s config class (via GET /api/custom-sources/{name}/config-schema). You pick a stream and fill in the fields. Fields whose names contain key, secret, password, token, credential or auth are masked. The platform then calls the source’s check_connection(), with a 30-second timeout.
Test locally
Section titled “Test locally”The repository includes a CLI for developing sources without the UI:
make list-sources # sources and their streamsmake test-source SOURCE=pokeapi STREAM=pokemon # check_connection()make fetch-source SOURCE=pokeapi STREAM=pokemon # print 5 records from get()make run-source SOURCE=pokeapi STREAM=pokemon # full pipeline to the logger destinationThe targets wrap python -m bizon_platform.cli.test_source {list|check|fetch|run|streams}. Config values are merged in this order, each overriding the previous:
- Environment variables named
<SOURCE>_<FIELD>, for exampleBUILDBETTER_API_KEYsetsapi_key. --config-file path.json. If the path doesn’t exist, the CLI tries.secrets/<source>.json.--config '{"api_key": "..."}'.
uv run python -m bizon_platform.cli.test_source fetch buildbetter signals \ --config-file .secrets/buildbetter.json --limit 3 --rawThe CLI doesn’t read .env. scripts/test_source.py <source> <stream> [--fetch] does, if you prefer to keep keys there.