Recursos
Atrás

A place for AI forward engineers and leaders

Watch sessions on building AI agents grounded in your governed data.

Watch now
"DOMO // BUILD" text over a dark grid background with white and light blue lettering.
Acerca de
Atrás
Premios
Recognized as a Leader for
32 consecutive quarters
Primavera de 2025: líder en BI integrada, plataformas de análisis, inteligencia empresarial y herramientas ELT
Fijación

Building Data Pipelines in Python: Frameworks, Examples, and Best Practices

3
min read
Monday, June 15, 2026
Table of contents
Carrot arrow icon

Building data pipelines in Python involves choosing the right framework for your needs, implementing reliable extraction and transformation logic, and avoiding common pitfalls that derail production systems. This guide compares six major orchestration tools, walks through code examples for each pipeline stage, and explains the differences between pipelines, ETL, and ELT. You will also find guidance on performance optimization, data quality validation, and monitoring strategies.

Key takeaways

Here are the main points to keep in mind:

  • Python data pipelines automate the flow of data from source to destination through extraction, transformation, and loading stages
  • Six major frameworks (Airflow, Prefect, Dagster, Luigi, Dask, Apache Beam) each serve different use cases based on team size, complexity, and compute needs
  • Data pipelines and ETL are related but distinct: pipelines are the broader infrastructure, while ETL describes a specific pattern within them
  • Building production-ready pipelines requires attention to monitoring, error handling, idempotency, and data quality validation beyond basic functionality
  • Python's extensive library ecosystem and readability make it the most popular language for data pipeline development

What are data pipelines in Python?

Think of data pipelines as assembly lines for information. In Python, data pipelines are structured workflows designed to move, transform, and process data from one point to another in a systematic, automated way. Raw data enters. It passes through cleaning, filtering, aggregating, or enriching steps. It emerges ready for analysis or storage.

Every data pipeline follows a core lifecycle, regardless of the tools you use to build it:

  1. Extract: Pull data from source systems such as application programming interfaces (APIs), databases, flat files, or cloud storage
  2. Transform: Clean, validate, reshape, and enrich the data to match your target schema and business logic
  3. Load: Deliver the processed data to its destination, whether a data warehouse, dashboard, or machine learning model

Pipelines can operate in two primary modes. Batch pipelines process data on a schedule, running hourly, daily, or weekly to move accumulated records. Streaming pipelines process data continuously in near-real time, handling events as they arrive. Python supports both approaches, though batch processing remains the more common starting point for most teams.

These steps can be written in Python using libraries like Pandas or the built-in csv module, or with specialized tools like Apache Airflow, Luigi, or Prefect for orchestration. The goal is to ensure that data flows efficiently and consistently from its source through transformation steps and into a target system like a data warehouse, dashboard, or machine learning model.

Because Python integrates easily with both data sources and storage solutions, it's widely used for building pipelines that can handle anything from small-scale ETL (Extract, Transform, Load) processes to large-scale, distributed workflows.

Why build data pipelines in Python

Python has become the default language for data pipeline development. Many of the world's leading names in technology (including Google, Amazon, OpenAI, and Quora) rely on Python for its comprehensive features and scalability. This widespread adoption means battle-tested patterns and solutions exist for nearly every pipeline challenge you'll encounter.

Several characteristics make Python particularly well-suited for pipeline work:

  • Readability and maintainability: Python's clean syntax means pipelines are easier to write, review, and debug. New team members can understand existing code faster, and maintenance becomes less painful over time.
  • Extensive library ecosystem: Libraries like Pandas, NumPy, SQLAlchemy, and requests handle everything from data manipulation to database connections to API calls. You rarely need to build functionality from scratch.
  • Strong community support: When you hit a problem, chances are someone has solved it before. Stack Overflow answers, GitHub repositories, and detailed documentation make troubleshooting easier.
  • Integration flexibility: Python connects easily to virtually any data source or destination (structured query language (SQL) databases, non-relational (NoSQL) stores, representational state transfer (REST) APIs, cloud storage, message queues, and more).
  • Open-source foundation: No licensing fees for Python or most of its data libraries. You get enterprise-grade capabilities without enterprise-grade costs.

Python is not an ETL tool itself. It is a general-purpose programming language. Tools in this space include orchestrators like Airflow, transformation tools like dbt, and managed ingestion platforms like Fivetran. Python is what you use to write the logic that runs inside those platforms, or to build simpler pipelines that don't need a full orchestration layer.

Data pipeline vs ETL: understanding the difference

The terms "data pipeline" and "ETL" often get used interchangeably, but they describe different things. Understanding the distinction helps you communicate clearly with your team and choose the right approach for your use case.

A data pipeline is the broader infrastructure that moves data from point A to point B. It encompasses the entire system: the connections to source systems, the processing logic, the destination targets, and the orchestration that ties everything together. Pipelines can be simple (a script that runs once a day) or complex (a distributed system processing millions of events per second).

ETL (Extract, Transform, Load) describes how data is processed within a pipeline. You extract data from sources, transform it in a staging area, and then load the cleaned data into your destination. The transformation happens before the data reaches its final home.

ELT (Extract, Load, Transform) flips the order. You extract data, load it directly into your destination (typically a cloud data warehouse), and then transform it there using the warehouse's processing power. ELT has become more popular as cloud warehouses like Snowflake and BigQuery have made compute cheap and scalable. Teams sometimes choose ELT simply because it's newer without considering whether their warehouse can handle the transformation load during peak hours. That's a recipe for performance problems.

Orchestration is yet another distinct concept. It's the mechanism that schedules, sequences, and monitors pipeline stages. Tools like Airflow, Prefect, and Dagster are orchestrators that coordinate when and how your pipeline steps run.

The following table clarifies when to use each term:

ConceptWhat It IsWhen to Use
Data PipelineThe complete infrastructure for moving and processing dataWhen discussing the overall system architecture
ETLA pattern where transformation happens before loadingWhen working with on-premise systems or when you need to minimize data warehouse compute
ELTA pattern where transformation happens after loadingWhen using cloud warehouses with cheap, scalable compute
OrchestrationThe scheduling and coordination layerWhen discussing how pipeline stages are triggered and monitored

Benefits of building data pipelines in Python

Organizations are inundated with massive volumes of big data from multiple sources. Pipelines make it possible to move data efficiently and consistently without constant manual oversight.

By using Python's rich ecosystem of libraries and frameworks, businesses can build custom pipelines around their specific requirements, whether for analytics, reporting, or powering machine learning.

Automated workflows

Python data pipelines remove the repetitive, manual work involved in moving and preparing data. Once a pipeline is built, it can automatically handle ingestion, transformation, and output according to a set schedule or triggers. Your team spends less time on tedious data handling. More time on analysis, innovation, and strategic decision-making.

Improved data quality

When data is processed manually, errors and inconsistencies are inevitable. Python data pipelines ensure every data set follows the same cleaning, validation, and formatting rules. This data consistency improves its reliability and makes it easier to trust the results of reports, dashboards, and predictive models.

Scalability and flexibility

As your business grows, so does the amount and variety of data you handle. Python pipelines are highly adaptable, allowing you to scale from small ETL jobs to processing massive data sets across distributed systems. They can also be modified quickly to accommodate new data sources, formats, and processing logic without a complete rebuild.

Integration with multiple data sources

Python has a vast ecosystem of libraries and connectors that make it easy to pull data from diverse sources such as APIs, SQL and NoSQL databases, spreadsheets, and cloud storage. This ability to combine data from many systems into a single workflow creates a more complete and unified view of your operations.

Reproducibility

A well-defined pipeline ensures that the same steps can be executed repeatedly with identical results. This reproducibility is crucial for auditing, regulatory compliance, and verifying analytics or machine learning results.

Shorter time to insight

By streamlining the entire data process (from ingestion to transformation to loading) Python pipelines significantly reduce the time between receiving raw data and producing analysis-ready data sets. This speed helps decision-makers act sooner.

Cost efficiency

Automating your data workflows reduces the labor costs associated with manual handling and minimizes the impact of costly errors. Because Python is open-source and widely supported, you can also avoid high licensing fees while still making use of enterprise-grade capabilities.

How to build data pipelines in Python

Building a data pipeline in Python involves creating a streamlined process for collecting, transforming, and delivering data from various sources to a target system. While the specific tools and libraries you use may vary, the overall process typically follows a series of structured steps to ensure your data flows smoothly and reliably.

1. Define your requirements

Before writing any code, clearly outline what your pipeline should achieve. Identify your data sources, the transformations required, the target destination, and the frequency of data movement. Skip this step, and you'll likely rebuild the pipeline three times before getting it right.

2. Choose your tools and libraries

Select Python libraries that match your requirements. Common choices include Pandas for data manipulation, SQLAlchemy for database connections, requests for API calls, and orchestration tools like Apache Airflow, Luigi, or Prefect for scheduling and automation.

3. Set up data ingestion

Write scripts to extract data from your chosen sources, such as APIs, databases, flat files, or cloud storage. Use connectors or APIs that support authentication, error handling, and retries to ensure data is pulled reliably.

Here's a simple example of extracting data from a REST API:

import requests
import pandas as pd

def extractfromapi(url, headers=None):
response = requests.get(url, headers=headers, timeout=30)
response.raiseforstatus()
return pd.DataFrame(response.json())


4. Clean and transform the data

Implement data cleaning steps to remove duplicates, handle missing values, and standardize formats. Apply transformations that align the data with your target schema, business logic, or analytical requirements, using tools like Pandas or PySpark.

A basic transformation might look like this:

def transformsalesdata(df):
# Remove duplicates
df = df.dropduplicates(subset=['transactionid'])

# Handle missing values
df['quantity'] = df['quantity'].fillna(0)

# Standardize date format
df['saledate'] = pd.todatetime(df['saledate'])

# Calculate derived field
df['totalamount'] = df['quantity'] * df['unitprice']

return df


5. Load the data into the destination

Send the processed data to your target system, whether that is a relational database, a data warehouse like Snowflake or BigQuery, or a cloud storage bucket. Ensure the load process is idempotent so it can run repeatedly without creating duplicates or inconsistencies. Using simple INSERT statements instead of upsert/merge logic causes duplicate records when pipelines are re-run after failures. And that's a detail many guides miss.

6. Orchestrate and automate the pipeline

Use a scheduling tool to run the pipeline on a set schedule or in response to events. Orchestration ensures dependencies are respected and tasks run in the correct order. Tools like Airflow allow you to monitor pipeline health and troubleshoot failures quickly.

For production pipelines, two patterns are essential. Idempotency means a pipeline run can be safely re-executed without duplicating or corrupting data (typically achieved through upsert/merge logic rather than simple appends). Retry with exponential backoff handles transient failures gracefully by waiting progressively longer between attempts before giving up.

7. Monitor and maintain the pipeline

Set up logging, alerts, and dashboards to track pipeline performance, data quality, and run status. Regularly review and update the pipeline to accommodate changes in data sources, formats, or business requirements.

Key metrics to track include:

  • Data freshness: Time since the last successful pipeline run
  • Row volume: Expected vs actual record counts (sudden drops or spikes signal problems)
  • Null rate: Percentage of missing values in critical fields
  • Error rate: Frequency and types of failures
  • Runtime duration: How long each stage takes (useful for spotting degradation)

Use structured logging that includes run identifiers, batch IDs, and timestamps so you can trace issues back to specific executions. Never log secrets, credentials, or personally identifiable information. Sanitize your logs to avoid creating security vulnerabilities.

Python data pipeline frameworks compared

Here's a quick tour of popular Python frameworks you can use to build, orchestrate, and scale data pipelines. They vary in focus from distributed compute to workflow orchestration to project structure, so the "best" choice depends on your team size, reliability needs, and where your bottlenecks are (compute vs coordination vs maintainability).

The following table summarizes the key differences:

FrameworkBest ForLearning CurveStreaming Support
Apache AirflowEnterprise orchestration with complex dependenciesSteepLimited (batch-first)
PrefectTeams wanting Python-native orchestration with less boilerplateGentleLimited
DagsterAnalytics engineering teams prioritizing data quality and lineageModerateLimited
LuigiSimple batch workflows in stable environmentsGentleNone
DaskScaling Pandas/NumPy operations horizontallyModerateLimited
Apache BeamUnified batch and streaming with multi-cloud portabilitySteepFull

Apache Airflow

Airflow is a battle-tested scheduler/orchestrator that represents workflows as DAGs (directed acyclic graphs) in Python. It was listed as the #1 best Python ETL tool by Estuary. With a huge ecosystem of operators and a mature user interface (UI), it's a common choice for coordinating SQL jobs, Spark tasks, and external systems, though it can add setup and maintenance overhead. Verbose DAG code and a batch-first mindset are part of the package; streaming requires add-ons.

Prefect

Prefect is an orchestration tool that emphasizes developer ergonomics: You write "flows" and "tasks" as normal Python, add decorators for retries/caching, and get a cloud or self-hosted control plane for observability. It's flexible and easy to adopt, especially for teams that want less boilerplate than Airflow.

Dagster

Dagster is a modern orchestrator centered on software-defined assets (data products) with strong typing, input/output (IO) managers, and built-in observability. It encourages testing and modularity, making lineage and deployments first-class. Great for teams that want maintainable, production-grade pipelines with clear contracts between steps.

Luigi

Luigi (from Spotify) is a lightweight Python framework for building batch pipelines via tasks with explicit dependencies and targets (usually files or tables). Simple and stable. Good for on-prem or smaller setups, though it lacks some of the UI polish, scheduling features, and ecosystem breadth of newer tools.

Dask

Dask provides parallel and distributed computing in pure Python with familiar NumPy/Pandas/SciPy-like APIs. It's ideal when your pipeline is compute-bound (e.g., large dataframe transforms) and you want to scale horizontally without rewriting code for Spark. Dask is not an orchestrator. Pair it with one if you want scheduling and retries.

Apache Beam

Beam is a unified model for batch and streaming data processing. You write pipelines once in Python and execute them on multiple runners, like Google Cloud Dataflow, Apache Flink, or Apache Spark. It shines when you need windowing, exactly-once semantics, and portability across engines.

How to choose the right framework for your pipeline

With so many Python frameworks for data pipelines, it's easy to get lost in the feature lists. The best choice depends on your priorities: Are you optimizing for raw compute performance, ease of orchestration, project maintainability, or deployment flexibility?

Rather than comparing features in the abstract, consider these conditional guidelines:

If your team needs a visual DAG interface and enterprise scheduling with a large plugin ecosystem, Airflow is a common choice, though it can add setup and maintenance overhead. It is particularly strong when you are integrating SQL jobs, Spark tasks, and external systems across a mixed-tech environment.

If you want Python-native syntax with minimal boilerplate and a gentler learning curve, Prefect or Dagster are easier starting points. Prefect emphasizes flexibility and fast iteration, while Dagster adds built-in data quality and lineage features that analytics engineering teams appreciate.

If your biggest bottleneck is processing large datasets and you want to scale Pandas/NumPy-like operations horizontally, Dask is the right compute framework. Remember that Dask handles the processing. You'll still want an orchestrator like Airflow or Prefect for scheduling and monitoring.

If you need unified batch and streaming with portability across cloud providers, Apache Beam offers that flexibility at the cost of a steeper learning curve.

Simple, dependency-driven workflows without the complexity of heavier orchestrators? Luigi works well for small teams running batch jobs in stable, predictable environments.

Optimizing Python pipeline performance

Once your pipeline works correctly, the next challenge is making it work efficiently. Performance optimization becomes critical as data volumes grow and latency requirements tighten.

Several techniques can dramatically improve pipeline performance:

  • Use generators instead of loading entire datasets into memory. Generators process data row by row or in chunks, keeping memory usage constant regardless of file size.
  • Chunk large datasets when reading from databases or files. Processing 10,000 rows at a time is often more efficient and uses less memory than loading millions of rows at once.
  • Use multiprocessing for central processing unit (CPU)-bound transformations. Python's multiprocessing library lets you parallelize work across cores, though be mindful of the overhead for small datasets.
  • Profile before optimizing. Use tools like cProfile or lineprofiler to identify actual bottlenecks rather than guessing. The slowest part of your pipeline is often not where you expect.
  • Batch database operations. Instead of inserting rows one at a time, use bulk insert operations. The difference can be orders of magnitude.

One pattern that bridges performance and reliability is staging data before committing to the destination. Write transformed data to a temporary table or staging location first, validate it, and then atomically swap or merge it into the final destination. This approach prevents partial loads from corrupting downstream data and allows safe reruns if something fails mid-process.

Common pipeline challenges and how to avoid them

Even well-designed pipelines encounter problems. Knowing the failure modes helps you build more resilient systems from the start.

The following challenges appear frequently in production pipelines:

  • Schema drift: Upstream source schemas change unexpectedly. A column gets renamed, a data type changes, or new fields appear. Build schema validation into your ingestion step and set up alerts when schemas don't match expectations.
  • Dependency failures: External APIs go down, databases become unavailable, or network connections time out. Implement retry logic with exponential backoff and circuit breakers to handle transient failures gracefully.
  • Data volume spikes: A sudden increase in data volume can overwhelm your pipeline, causing timeouts or memory errors. Design for horizontal scaling and monitor volume trends to anticipate capacity needs.
  • Silent data quality issues: Bad data slips through without triggering errors. Null values where you expect numbers, duplicates that inflate metrics, or encoding issues that corrupt text. Add explicit validation checks rather than assuming data is clean.
  • Credential expiration: API tokens and database passwords expire, breaking pipelines that ran fine for months. Centralize credential management and set up rotation reminders.
  • Backfill complexity: Reprocessing historical data after a bug fix or schema change is harder than it should be. Design pipelines with backfill in mind from the start, using date partitioning and idempotent loads.

Data quality and validation basics

Data quality problems are among the most common and costly pipeline failures. A quality gate is a validation check that runs at a specific pipeline stage before data moves downstream. Implementing these gates catches problems early, before bad data propagates through your entire system.

Two types of validation cover most needs. Schema validation checks that incoming data matches expected column names, types, and constraints. If your source suddenly starts sending strings where you expect integers, schema validation catches it immediately. Completeness checks verify that required fields are populated and that you received the expected number of records.

Python offers several tools for implementing quality gates. Pandera provides schema validation for Pandas DataFrames with a declarative syntax. Great Expectations offers a more comprehensive framework for defining, documenting, and validating data expectations. Both integrate well with orchestration tools. Don't implement validation so strict that normal data variations trigger false alarms. You'll train your team to ignore alerts.

Where you place validation matters. Pre-load validation catches bad data before it enters your destination, preventing downstream contamination. Post-load validation confirms the load completed correctly (row counts match, no duplicates were introduced, and critical fields are populated). Most production pipelines benefit from both.

Python data pipeline examples in practice

Python is a versatile language for building data pipelines, from small ETL scripts to large-scale distributed systems. Its rich ecosystem of libraries and frameworks makes it possible to connect to virtually any data source, transform data in flexible ways, and integrate with visualization or analytics platforms.

Below are examples of Python-based data pipelines and the kinds of problems they solve.

ETL for sales data aggregation

This pipeline generates daily dashboards for an e-commerce analytics team.

  • Tools: Pandas, SQLAlchemy, Airflow/Dagster for orchestration
  • Extract: Query daily sales transactions from a PostgreSQL database using SQLAlchemy
  • Transform: Clean the data with Pandas (remove duplicates, standardize currency, convert time zones)
  • Load: Insert aggregated daily metrics (total sales, average order value, top products) into a data warehouse like Snowflake or BigQuery

Social media sentiment analysis

This pipeline tracks brand sentiment for marketing campaigns.

  • Tools: Tweepy (Twitter API), Dask, scikit-learn, Prefect for orchestration
  • Extract: Pull tweets from a specific hashtag or account via the Twitter API
  • Transform: Use Dask to parallelize text preprocessing (tokenization, stopword removal)
  • Analyze: Apply a sentiment analysis model with scikit-learn
  • Load: Store results in Elasticsearch for querying or in a BI tool for visualization

Fraud detection pipeline

This pipeline prevents fraudulent purchases in a financial platform.

  • Tools: Apache Beam (running on Google Cloud Dataflow), BigQuery
  • Extract/Stream: Ingest credit card transactions in near-real time from a Kafka topic
  • Transform: Apply Beam's windowing to analyze transaction patterns over rolling five-minute intervals
  • Detect: Flag anomalies based on spending thresholds or velocity checks
  • Load/Alert: Store flagged transactions in BigQuery and send alerts via a webhook to a fraud monitoring system

Machine learning model training pipeline

This pipeline automates weekly retraining of recommendation algorithms.

  • Tools: Kedro for structure, scikit-learn or TensorFlow, MLflow for tracking
  • Extract: Pull labeled training data from cloud storage
  • Transform: Apply feature engineering and normalization
  • Train: Fit a machine learning model and log results with MLflow
  • Evaluate and Deploy: Save the model artifact, push to a model registry, and trigger deployment

Website log analysis

This pipeline monitors website performance trends.

  • Tools: Luigi, Pandas, Matplotlib
  • Extract: Read Apache/Nginx access logs from an Amazon Simple Storage Service (S3) bucket
  • Transform: Parse logs into structured data with Pandas, filtering for status codes and paths
  • Load/Visualize: Generate plots for daily traffic, errors, and request latency

From Python pipelines to actionable insights with Domo

Python offers a powerful, flexible foundation for building data pipelines. Whether you're orchestrating complex workflows, scaling compute-intensive jobs, or simply automating routine data tasks, Python is a great choice. The right framework depends on your specific needs, but every pipeline benefits from a clear path from raw data to information you can use.

That's where Domo comes in. By connecting your Python-powered pipelines to Domo's BI platform, you can transform processed data into interactive dashboards, real-time reports, and shareable insights that support clear decisions.

Ready to see how Domo can enhance your Python data workflows? Explore how Domo integrates with your data pipelines.

See your pipelines come to life in Domo

Turn Python ETL/ELT outputs into monitored, shareable dashboards and real-time alerts.

Build faster, safer data workflows—free

Connect sources, validate data quality, and track freshness without babysitting every run.
See Domo in action
Watch Demos
Start Domo for free
Free Trial

Frequently asked questions

No items found.
No items found.
Explore all
No items found.
Dataflows & Integration