CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-airbyte-source-notion

Airbyte source connector for extracting data from Notion workspaces with OAuth2.0 and token authentication support.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

connector-setup.mddocs/

Connector Setup

Core functionality for initializing and configuring the Airbyte Notion source connector with authentication and stream management.

Capabilities

Main Connector Class

The primary connector class that orchestrates data extraction from Notion workspaces.

class SourceNotion(YamlDeclarativeSource):
    """
    Main Airbyte source connector for Notion API integration.
    Extends YamlDeclarativeSource to combine declarative YAML configuration
    with custom Python streams for complex operations.
    """
    
    def __init__(self):
        """
        Initializes the connector with manifest.yaml configuration.
        Sets up declarative streams and prepares for custom stream injection.
        """
    
    def streams(self, config: Mapping[str, Any]) -> List[Stream]:
        """
        Returns complete list of available streams including both declarative
        and custom Python streams.
        
        Args:
            config: Connector configuration containing authentication and sync settings
            
        Returns:
            List of Stream objects for data extraction
        """
    
    def _get_authenticator(self, config: Mapping[str, Any]) -> TokenAuthenticator:
        """
        Creates and returns the appropriate authenticator based on configuration.
        Supports OAuth2.0, token-based, and legacy authentication methods.
        
        Args:
            config: Configuration mapping containing credentials
            
        Returns:
            TokenAuthenticator configured for the specified auth method
        """

Entry Point Function

The main entry point for command-line execution of the connector.

def run():
    """
    Main entry point for the Airbyte source connector.
    Initializes SourceNotion and launches with command line arguments.
    Used by the source-notion console script.
    """

Usage Examples

Basic Connector Initialization

from source_notion import SourceNotion

# Initialize the connector
source = SourceNotion()

# OAuth2.0 configuration
oauth_config = {
    "credentials": {
        "auth_type": "OAuth2.0",
        "client_id": "your_client_id",
        "client_secret": "your_client_secret",
        "access_token": "your_oauth_token"
    },
    "start_date": "2023-01-01T00:00:00.000Z"
}

# Get available streams
streams = source.streams(oauth_config)
print(f"Available streams: {[stream.name for stream in streams]}")

Token-Based Authentication

# Token authentication configuration
token_config = {
    "credentials": {
        "auth_type": "token",
        "token": "secret_integration_token"
    },
    "start_date": "2023-01-01T00:00:00.000Z"
}

# Initialize and configure
source = SourceNotion()
streams = source.streams(token_config)

# Test authenticator creation
authenticator = source._get_authenticator(token_config)

Legacy Configuration Support

# Legacy format (backward compatibility)
legacy_config = {
    "access_token": "notion_token",
    "start_date": "2023-01-01T00:00:00.000Z"
}

source = SourceNotion()
authenticator = source._get_authenticator(legacy_config)

Command Line Usage

# Using as installed console script
source-notion spec
source-notion check --config config.json
source-notion discover --config config.json
source-notion read --config config.json --catalog catalog.json

# Using Python module directly
python -m source_notion.run spec
python -m source_notion.run check --config config.json

Integration with Airbyte CDK

from airbyte_cdk.models import AirbyteConnectionStatus, Status
from airbyte_cdk.logger import AirbyteLogger

logger = AirbyteLogger()
source = SourceNotion()

# Test connection
config = {
    "credentials": {
        "auth_type": "token",
        "token": "your_token"
    }
}

try:
    status = source.check(logger, config)
    if status.status == Status.SUCCEEDED:
        print("Connection successful!")
    else:
        print(f"Connection failed: {status.message}")
except Exception as e:
    print(f"Error testing connection: {e}")

Configuration Validation

The connector automatically handles configuration validation and provides clear error messages for common issues:

  • Missing Credentials: Validates that either OAuth2.0 or token credentials are provided
  • Invalid Date Format: Ensures start_date follows the required ISO format
  • Authentication Errors: Provides specific guidance for permission and access issues
  • Backward Compatibility: Automatically handles legacy configuration formats

Stream Architecture

The connector uses a hybrid approach:

  1. Declarative Streams (defined in manifest.yaml):

    • users
    • databases
    • comments
  2. Custom Python Streams (injected by SourceNotion.streams()):

    • pages (parent stream for blocks)
    • blocks (substream with recursive traversal)

This architecture allows leveraging Airbyte's low-code declarative framework while maintaining flexibility for complex operations like hierarchical block traversal.

Install with Tessl CLI

npx tessl i tessl/pypi-airbyte-source-notion

docs

connector-setup.md

data-streams.md

index.md

stream-management.md

transformations.md

tile.json