spark-python-data-source

Build custom PySpark DataSource connectors for batch and Structured Streaming.

1|Updated Apr 24, 2026
One-click install
npx skills add https://github.com/itsadijmbt/SecureMCP-Servers --skill spark-python-data-source-itsadijmbt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spark-python-data-source
Source: https://github.com/itsadijmbt/SecureMCP-Servers/tree/main/TEST_SERVERS/PORTED_TO_SECUREMCP/databrickslab-mcp/ai-dev-kit/databricks-skills/spark-python-data-source
Command: npx skills add https://github.com/itsadijmbt/SecureMCP-Servers --skill spark-python-data-source-itsadijmbt

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you build custom Apache Spark data sources in Python so Spark can reliably read from and write to external systems when no native connector exists.

Core Features & Use Cases

  • Batch + Streaming DataSource API: Implement readers/writers for both batch and Structured Streaming by following the required PySpark DataSource interfaces.
  • Production-ready connector patterns: Cover partitioning strategies, option handling, authentication fallbacks, type conversion, offset management, retries/backoff, and error resilience.
  • Executor-safe implementation guidance: Ensure third-party imports occur on executors and keep inheritance flat to avoid serialization issues.

Use Case Example: You need to load event data from a REST API into Spark continuously; implement a streaming reader that paginates, converts external types to Spark schema, manages offsets for incremental reads, and applies resilient error handling.

Quick Start

Ask: “Using the spark-python-data-source skill, design a PySpark DataSourceReader and DataSourceWriter for a REST API that supports both batch and streaming, including partitioning, OAuth2 authentication, type conversion, and exactly-once-style streaming offset handling.”

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 PySpark data source connector for an external REST API?

To build a custom PySpark data source connector, implement the DataSourceReader and DataSourceWriter interfaces to handle reading from and writing to external systems. You must manage partitioning, option handling, and executor-local imports to ensure reliable Spark DataFrame integration.

How does Structured Streaming offset management work for custom PySpark data sources?

Structured Streaming offset management tracks incremental read positions by implementing DataSourceStreamReader and DataSourceStreamWriter. This handles continuous data ingestion from external systems, ensuring resilient exactly-once-style streaming by persisting offsets across micro-batches.

Why does my PySpark custom connector fail with serialization errors on executors?

PySpark custom connector serialization errors occur when inheritance is not flat or third-party imports happen on the driver. To fix this, keep inheritance single-level and move third-party imports to executor-local scopes to avoid serialization failures during distributed execution.

Can I implement both batch and Structured Streaming reads in one custom Spark data source?

Yes, you can implement both batch and Structured Streaming reads in a custom Spark data source by implementing the respective DataSourceReader and DataSourceStreamReader interfaces. This requires handling bidirectional type conversion and authentication priority chains for both contexts.

What is the best way to handle authentication in a custom PySpark data source connector?

The best way to handle authentication in a custom PySpark data source connector is implementing an authentication priority chain with fallbacks. This pattern securely manages credentials across driver and executor boundaries while maintaining robust error handling during external system access.

How do I convert external API data types to a Spark schema in a custom data source?

To convert external API data types to a Spark schema in a custom data source, implement bidirectional type conversion within your DataSourceReader. This maps external system schemas to Spark DataFrame types, ensuring data compatibility during both batch reads and streaming ingestion.