Skip to content

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.py

Docker Compose and the Helm chart mount this directory at /custom_sources in the API and worker containers.

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.

from typing import List, Tuple
from bizon.source.config import SourceConfig
from bizon.source.models import SourceIteration, SourceRecord
from bizon.source.source import AbstractSource
from 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
)
MethodRequiredPurpose
streams()yesStatic. The stream names.
get_config_class()yesStatic. A SourceConfig subclass with your extra fields.
get_authenticator()yesA requests AuthBase, or None. It is attached to self.session.
check_connection()yesReturns (ok, error_message).
get_total_records_count()yesTotal records if known, else None.
get(pagination)yesReturns one page as a SourceIteration. Called until next_pagination is empty.
get_records_after(source_state, pagination)noFor incremental syncs.

self.session is a requests session that bizon sets up for you. See Custom sources in the Bizon reference for more.

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.

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.py becomes my_api.
  • .zip: must contain a source.py. The directory is named after the zip’s top-level folder, or the zip itself. Only source.py is 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 keeps CUSTOM_SOURCES_DIR in step with a folder in a Git repository, so sources go through code review instead of uploads.

VariableDefaultDescription
GIT_SYNC_ENABLEDfalseTurn on Git sync
GIT_SYNC_REPO_URLRepository URL, e.g. https://github.com/acme/bizon-sources.git
GIT_SYNC_BRANCHmainBranch to sync
GIT_SYNC_PATHcustom_sourcesFolder in the repository that holds the sources
GIT_SYNC_TOKENAccess token for private HTTPS repositories
GIT_SYNC_WEBHOOK_SECRETShared secret for push webhooks
  1. The API does a shallow (depth 1), sparse fetch of GIT_SYNC_PATH from GIT_SYNC_BRANCH.
  2. Every subdirectory of that folder that contains a source.py replaces the directory of the same name in CUSTOM_SOURCES_DIR.
  3. 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.

Set GIT_SYNC_WEBHOOK_SECRET on the API, then add a webhook to the repository:

SettingGitHubGitLab
URLhttps://<host>/api/custom-sources/git-sync/webhooksame
Content typeapplication/json(always JSON)
SecretSecret = GIT_SYNC_WEBHOOK_SECRETSecret token = GIT_SYNC_WEBHOOK_SECRET
EventsJust the push eventPush 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:

Terminal window
python -c "import secrets; print(secrets.token_hex(32))"

The webhook is exempt from ADMIN_PASSWORD. It authenticates with the secret alone.

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.

The repository includes a CLI for developing sources without the UI:

Terminal window
make list-sources # sources and their streams
make 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 destination

The 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:

  1. Environment variables named <SOURCE>_<FIELD>, for example BUILDBETTER_API_KEY sets api_key.
  2. --config-file path.json. If the path doesn’t exist, the CLI tries .secrets/<source>.json.
  3. --config '{"api_key": "..."}'.
Terminal window
uv run python -m bizon_platform.cli.test_source fetch buildbetter signals \
--config-file .secrets/buildbetter.json --limit 3 --raw

The CLI doesn’t read .env. scripts/test_source.py <source> <stream> [--fetch] does, if you prefer to keep keys there.