Airbyte source connector for extracting data from the Xero accounting API with support for 21 data streams and incremental sync capabilities
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Main connector functionality providing the primary interface for Airbyte framework integration. The SourceXero class serves as the entry point for all connector operations including connection validation, stream discovery, and data extraction.
The main connector class that inherits from Airbyte's YamlDeclarativeSource, providing all standard Airbyte source functionality with Xero-specific configuration.
from typing import Tuple
from airbyte_cdk.sources.declarative.yaml_declarative_source import YamlDeclarativeSource
class SourceXero(YamlDeclarativeSource):
"""
Main Airbyte source connector for Xero API.
Inherits from YamlDeclarativeSource to provide declarative configuration
support using manifest.yaml for stream definitions.
"""
def __init__(self):
"""
Initialize the Xero source connector.
Automatically loads configuration from manifest.yaml file in the
source_xero package directory.
"""
def check_connection(self, logger, config: dict) -> Tuple[bool, str]:
"""
Test connection to Xero API using provided configuration.
Args:
logger: Python logger instance for diagnostic output
config (dict): Connection configuration containing access_token,
tenant_id, and start_date
Returns:
Tuple[bool, str]: (success_status, error_message)
- (True, None) for successful connection
- (False, error_details) for failed connection
Raises:
Various HTTP and authentication exceptions based on Xero API response
"""
def streams(self, config: dict) -> list:
"""
Discover and return all available data streams for the connector.
Args:
config (dict): Connection configuration
Returns:
list: List of configured stream objects (21 total streams)
Each stream object contains metadata, schema, and sync methods
"""Command-line entry point function that initializes the connector and launches it through Airbyte's framework.
def run():
"""
Main entry point for running the Xero source connector.
Creates a SourceXero instance and launches it using Airbyte CDK's
launch function with command-line arguments from sys.argv.
This function is registered as the 'source-xero' console script
in the package's pyproject.toml configuration.
Usage:
Called automatically when running 'source-xero' command or
when executing the main.py module directly.
"""from source_xero import SourceXero
import logging
# Create logger
logger = logging.getLogger(__name__)
# Initialize connector
source = SourceXero()
# Configuration with required fields
config = {
"access_token": "your_xero_access_token_here",
"tenant_id": "your_xero_tenant_id_here",
"start_date": "2023-01-01T00:00:00Z"
}
# Test connection
is_connected, error = source.check_connection(logger, config)
if is_connected:
print("Successfully connected to Xero API")
else:
print(f"Connection failed: {error}")from source_xero import SourceXero
source = SourceXero()
config = {
"access_token": "your_token",
"tenant_id": "your_tenant",
"start_date": "2023-01-01T00:00:00Z"
}
# Get all available streams
streams = source.streams(config)
print(f"Total available streams: {len(streams)}")
# Stream information
for stream in streams:
print(f"Stream Name: {stream.name}")
print(f"Primary Key: {getattr(stream, 'primary_key', 'None')}")
print(f"Supports Incremental: {hasattr(stream, 'incremental_sync')}")
print("---")
# Expected output includes 21 streams:
# bank_transactions, contacts, credit_notes, invoices, manual_journals,
# overpayments, prepayments, purchase_orders, accounts, bank_transfers,
# employees, items, payments, users, branding_themes, contact_groups,
# currencies, organisations, repeating_invoices, tax_rates, tracking_categoriesfrom source_xero.run import run
import sys
# Simulate command line arguments
sys.argv = ['source-xero', 'check', '--config', 'config.json']
# Run the connector
run() # This will execute the check commandThe SourceXero class integrates seamlessly with Airbyte's standard protocols:
The connector follows Airbyte's declarative pattern where stream configuration, authentication, pagination, and data transformation are defined in the manifest.yaml file rather than in Python code.
Install with Tessl CLI
npx tessl i tessl/pypi-airbyte-source-xero