For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Building a custom source

Step-by-step reference for building a custom Nilus source: Git repo sync configuration, the implementation contract, source options, and troubleshooting.

Custom sources extend Nilus to upstream systems that are not yet covered by a built-in connector. You implement a Python class, keep it in Git, and invoke it through a custom:// source address. Nilus still handles orchestration, destination writes, and incremental state when you implement it.

Use Custom query (SQL) first when the system is SQL-accessible. Use a custom source only when a first-party connector or a query: extract cannot model the source.

When to use a custom source

  • The upstream system is not in the supported source catalog.

  • You need source-specific authentication, pagination, or object modeling.

  • You want the ingestion logic in version-controlled Python that the team owns end-to-end.

Custom sources run as spec.type: batch pipelines only.

Requirements

Repository access and a compatible runtime are required before Nilus can run a custom source pipeline.

Repository access

Before each run, Nilus synchronizes the configured repository and discovers the source implementation. The discovery process determines which class serves the custom:// address.

  1. The runtime clones spec.repo.url with git-sync before the pipeline starts.

  2. It sets baseDir as the custom-resource directory and installs requirements.txt when present.

  3. It imports every top-level *.py file in baseDir and finds CustomSource subclasses.

  4. It instantiates the class matching the URI host: custom://RandomUserSource → RandomUserSource.

  5. It calls nilus_source(uri, table, **kwargs) and loads its @nilus.resource objects.

The URI host is the Python class name, case-sensitive. Nested packages are not scanned. Keep helper modules beside the top-level files.

Python runtime

The Nilus runtime runs on Python 3.13 (from Nilus 2.0.29; earlier versions ran Python 3.11). Your custom source code, and every package pinned in requirements.txt, must install and run on Python 3.13.

Implementation contract

Every custom source subclasses CustomSource from the nilus package:

Method
Required
Role

nilus_source(uri, table, **kwargs)

Yes

Return one @nilus.resource or a tuple of resources. This is the entrypoint Nilus executes.

handles_incrementality()

Yes

Return True only when your code owns the incremental cursor through nilus.current.resource_state(). Nilus then skips sink.options.incremental_strategy.

dlt_source() exists only as a backward-compatible alias. Implement nilus_source().

Define resources and source functions

Resources are generator functions decorated with @nilus.resource(). Register them from a function decorated with @nilus.source:

  • Yield one row or document at a time, with a stable shape.

  • Return a tuple of resources when the source creates multiple destination tables.

  • Use per-resource write_disposition when handles_incrementality() returns True.

Each resource becomes its own table in the destination schema named by sink.options.dest_table.

URI format

Input
Where it comes from
How to read it

Class to load

URI host (custom://MyCustomSource)

Must match the Python class name exactly.

uri

Full source.address

Parse query parameters with urllib.parse.

table

source.options.source_table

Logical resource name for this run. Keep it stable.

**kwargs

Pipeline knobs Nilus already understands

incremental_key, interval_start, interval_end, page_size, and related extract options.

Extra source.options keys

Forwarded as uppercase environment variables

For example, source.options.api_key becomes API_KEY.

Use the URI for connection-level or source-class parameters, and source.options for the resource-level options the custom source expects.

Parse connector-specific settings from the URI:

Project secrets into the URI with {ENV_VAR} placeholders and spec.use.projection. Do not hardcode credentials. See Secrets and projections.

Incremental loading

Return True from handles_incrementality() and persist a cursor on the resource state. Nilus stores that state between runs.

Store only the minimum cursor needed to resume safely. Leave handles_incrementality() as False when the sink strategy controls the load.

Pagination and errors

Yield pages as you fetch them. Close connections in finally. Re-raise after logging.

Add Python dependencies

Add a requirements.txt beside the *.py files in baseDir for packages not already in the Nilus image. Nilus runs pip install -r requirements.txt at startup.

requests is already available as nilus.sources.helpers.requests or the image's requests package.

Repository layout

Import siblings by module name:

Configure repository sync and credentials

Field
Required
Description

spec.repo.url

Yes

Git URL of the repository that contains your custom source code.

spec.repo.baseDir

Yes

Directory holding the top-level *.py files and optional requirements.txt.

spec.repo.syncFlags

No

Extra git-sync flags. Set --ref= to pin a branch, tag, or commit.

spec.repo.secretId

Private repos only

DataOS secret as <workspace>:<secret-name>.

Pinning a branch, tag, or commit (syncFlags)

Without syncFlags, git-sync clones the default branch. Pin an explicit ref so every run uses the same code:

Authenticating a private repo (secretId)

For a private repository, store the git credentials in a DataOS secret and reference it from spec.repo.secretId. Nilus projects that secret into the git-sync container, which reads exactly two keys:

Key
Description

GITSYNC_USERNAME

Git username, or token username such as x-token-auth on Bitbucket.

GITSYNC_PASSWORD

Password, personal access token, or app password.

  1. Create the secret (type: secret, key-value):

  1. Reference it from the pipeline as <workspace>:<secret-name> (the workspace the secret was created in):

A public repository needs url and baseDir, plus optional syncFlags.

spec.repo.secretId authenticates repo sync only. Source and sink credentials still come from the custom:// URI, source.options, a depot, or spec.use.projection. See Secrets and projections.

Sample Nilus config

Example in practice

Two files live in baseDir. random_users.py yields rows. nilus_custom_source.py is the class Nilus imports.

random_users.py:

nilus_custom_source.py:

Pipeline address: custom://RandomUserSource. Destination tables land in schema raw. The resource name becomes the table name.

Behavior and capabilities

  • Pipeline mode: spec.type: batch only.

  • Code loading: top-level *.py in spec.repo.baseDir; class name matches the URI host.

  • Object model: resources own table names and row shape.

  • Destination naming: dest_table is the schema; resource names are the tables.

  • Incrementality: source state wins when handles_incrementality() returns True.

Troubleshooting

Symptom
Likely cause
Resolution

custom baseDir not set in repo

Manifest has no spec.repo / baseDir.

Add spec.repo.url and spec.repo.baseDir.

Custom source 'X' not found. Available: …

URI host does not match a subclass in baseDir.

Match the class name exactly. Keep the class in a top-level *.py file.

Runtime cannot import the module

baseDir is wrong, or a sibling import uses a laptop-only path.

Import siblings as from random_users import ….

Repository clone fails

Runtime cannot reach or authenticate to Git.

Set spec.repo.secretId with GITSYNC_USERNAME / GITSYNC_PASSWORD.

Pipeline runs against stale code

No ref pinned.

Set spec.repo.syncFlags: ["--ref=main"].

pip warning on requirements.txt

File lists bundled packages or a bad pin.

Ship only extra dependencies.

Output schema changes unexpectedly

Yielded dictionaries lack a stable shape.

Normalize rows before yield.

Expected table name missing / extra table

dest_table included a table segment, or a resource name changed.

Use schema-only dest_table; keep resource names stable.

Pipeline restarts from the beginning

No cursor, or source-owned state is disabled.

Implement resource_state() and return True from handles_incrementality().

Best practices

  • Keep resources, the CustomSource wrapper, and helpers in separate files.

  • Validate parameters before opening connections.

  • Make retries and pagination explicit.

  • Never hardcode credentials. Use secret projection in the URI.

  • Test a bounded sample before scheduling production runs.

  • Document every URI query parameter beside the class.

Last updated

Was this helpful?