Singer SDK

0.53.6 · active · verified Sun Mar 29

The Singer SDK (Software Development Kit) is a Python framework for building Singer taps (data extractors) and targets (data loaders). It simplifies the creation of data connectors that are compliant with the open-source Singer Spec, handling much of the boilerplate code for configuration, schema discovery, state management, and data serialization. The library is actively maintained by Meltano and the Singer community, with frequent releases addressing bug fixes, new features, and deprecations.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to build a simple Singer tap that extracts data from a REST API. It defines a `RESTStream` for a 'users' endpoint and a `Tap` class to configure and discover this stream. The example uses environment variables for sensitive API credentials to ensure it can be run securely.

import os
from singer_sdk import Tap, Stream
from singer_sdk.streams import RESTStream
import singer_sdk.typing as th


class UsersStream(RESTStream):
    """Users stream."""

    name = "users"
    url_base = os.environ.get("API_URL", "https://api.example.com")
    path = "/users"
    primary_keys = ["id"]
    records_jsonpath = "$.data[*]"
    schema = th.PropertiesList(
        th.Property("id", th.IntegerType),
        th.Property("name", th.StringType),
        th.Property("email", th.StringType),
    ).to_dict()


class MyTap(Tap):
    """My custom tap."""

    name = "tap-myapi"
    config_jsonschema = th.PropertiesList(
        th.Property("api_url", th.StringType, required=True),
        th.Property("api_key", th.StringType, required=True, secret=True),
    ).to_dict()

    def discover_streams(self):
        return [UsersStream(self)]


# To run the tap (e.g., discover catalog or sync data):
# python -m your_tap_module --config config.json --discover > catalog.json
# python -m your_tap_module --config config.json --catalog catalog.json --state state.json > state_new.json

if __name__ == "__main__":
    MyTap.cli()

view raw JSON →