spark-python-data-source

Build custom Python DataSource connectors for Apache Spark batch and streaming reads and writes.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/Blackkadder/databricks-apps-and-agents-workshop --skill spark-python-data-source-blackkadder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spark-python-data-source
Source: https://github.com/Blackkadder/databricks-apps-and-agents-workshop/tree/main/.claude/skills/spark-python-data-source
Command: npx skills add https://github.com/Blackkadder/databricks-apps-and-agents-workshop --skill spark-python-data-source-blackkadder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Connecting Apache Spark to external systems often requires custom, production-ready connectors that handle batch and streaming reads/writes, executor-safe execution, partitioning, authentication, type mapping, and robust error handling; this Skill codifies patterns and templates to build those connectors reliably in Python.

Core Features & Use Cases

  • End-to-end connector patterns: Templates and class patterns for DataSource, reader/writer, batch and stream modes.
  • Execution safety: Guidance on executor-local imports, flat single-level inheritance for serializability, and resource cleanup.
  • Operational concerns: Partitioning strategies, authentication fallback chains, type conversion, streaming offsets, retries, circuit breakers, and dead-letter queues.
  • Testing & production: Unit/integration testing patterns, observability and metrics, configuration validation, and deployment hardening.
  • Use Case: Implement a Python Spark DataSource to read paginated REST API data in parallel, convert types, and write to an external system with OAuth2 and retry/backoff.

Quick Start

Create a Python DataSource for Spark that reads from a paginated REST API with time-based partitions, uses a fallback authentication chain, and writes results into a Spark DataFrame.

Frequently Asked Questions about spark-python-data-source

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a custom Python DataSource connector for Apache Spark?

Build a custom Python DataSource connector for Apache Spark using templates for DataSource, reader/writer, and batch and stream modes that ensure execution safety and handle partitioning. These patterns codify production-ready connectors to read from and write to external systems reliably in Python.

How do you handle authentication in PySpark external data source connectors?

Handle authentication in PySpark external data source connectors by applying a fallback authentication chain. This approach ensures secure access to external systems by sequentially attempting multiple authentication methods, such as OAuth2, if the primary method fails.

Does Apache Spark 4.0 support Python DataSource connectors for streaming workloads?

Yes, Apache Spark 4.0 supports Python DataSource connectors for both batch and streaming scenarios. These connectors handle continuous reads and writes from message queues or REST APIs using JSON-serializable offsets and robust retry patterns for operational resilience.

Why do my PySpark DataSource imports fail on worker executors?

PySpark DataSource imports fail on worker executors because the distributed environment lacks the required local dependencies. You must use executor-safe imports and flat single-level inheritance for serializable readers and writers to ensure proper execution across distributed Spark nodes.

What is the best way to read a paginated REST API in parallel using Spark?

Read a paginated REST API in parallel using Spark by implementing a custom Python DataSource with time-based partitioning. This approach applies partitioning strategies to distribute API requests across executors, converting types and writing results directly into a Spark DataFrame.

How do you manage streaming offsets and retries in a Spark Python connector?

Manage streaming offsets and retries in a Spark Python connector by utilizing JSON-serializable offsets for checkpointing and applying robust retry and error-handling patterns. This includes circuit breakers and dead-letter queues to handle operational failures without data loss.