惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
B
Blog
罗磊的独立博客
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Anatomy of Duck DB for Python Developers
Varun Joshi · 2026-05-17 · via DEV Community

Introduction - SQL without a Server

Pandas is widely used for data analysis and almost every data analyst or even data engineers utilize it for faster analysis with table like data structure called DataFrames.The drawback is that it suffers once the data goes beyond few GB's and spinning up a Postgres or a Redshift is an overkill for quick analysis.Duck DB fills this gap with Zero-setup columnar SQL.

Getting Started - zero config, instant power

DuckDb is an open source OLAP database management system designed for analytics and for running within the same process as the application.
It is lightweight, can work directly with data files in csv, parquet etc without needing a server.

Installation and first query

pip install duckdb - No ports to open, No configuration and No daemon

In-Memory and Persistent Database - Two Operating Modes

In-Memory

When DuckDB connection is created without specifying a file, a database lives entirely in RAM.

import duckdb
con = duckdb.connect()          # or duckdb.connect(':memory:')

Enter fullscreen mode Exit fullscreen mode

  • All data is stored in RAM and no files are written to disk
  • Extremely fast reads/writes since there is zero I/O overhead.
  • Data is completely lost when connection closes.
  • No file locking or concurrency concerns

Persistent Mode

When the user provides a location DuckDB can write the results to disk in .duckDb format.

con = duckdb.connect('my_database.duckdb')

Enter fullscreen mode Exit fullscreen mode

  • Tables,Schemas and indexes are persisted.
  • Uses a columnar storage format with compression and buffered I/O
  • Only one write connection at a time but multiple read connection are allowed.
  • Supports WAL(Write Ahead Logging) for crash recovery

Powerful Pattern

DuckDb allows you to mix both modes where user can start with in-memory and attach a persistent database or use copy/export to snapshot in-memory result to disk.

con = duckdb.connect()

#Query a CSV, transform it, save the result to a persistent file
con.execute("""
    COPY(SELECT region, SUM(sales) AS total FROM read_csv('data.csv')
         GROUP BY region
     )
    TO 'results.parquet' (FORMAT PARQUET)
""")

Enter fullscreen mode Exit fullscreen mode

Users gets the speed of In-Memory processing which accelerates the pipeline processing with an option to persist.

Reading files directly --CSV,PARQUET,JSON,Arrow,

Query CSV without loading into memory

Select * from read_csv('data_csv', auto_detect=true);

Enter fullscreen mode Exit fullscreen mode

-Auto detects delimiter, compression and data types
-Handles malformed rows gracefully
-Can read multiple CSVs at once read_csv('data/*.csv')

Parquet

Select * from read_parquet('data.parquet');
--even from S3 directly
Select * from read_parquet('s3://bucket/data/*.parquet');

Enter fullscreen mode Exit fullscreen mode

  • Exploits column pruning as it only reads columns you need
  • Leverages row group skipping using Parquet's build in min/max stats
  • Native support for nested types(structs,list,maps)

JSON/NDJSON

SELECT * FROM read_json('events.ndjson', auto_detect=true);

Enter fullscreen mode Exit fullscreen mode

-AUTO INFERS schema from data
-NDJSON(Newline delimited) streams efficiently line by line
-Can unnest deeply nested JSON fields using DuckDB's json_extract, UNNEST, or -> operators

Apache Arrow

import pyarrow as pa
arrow_table = pa.Table.from_pandas(df)
duckdb.query(""SELECT * from arrow_table""")

Enter fullscreen mode Exit fullscreen mode

-Zero copy integration: DuckDB reads from Arrow memory without serialization
-Ideal for pipelines where data never needs to touch disk

SQL Beyond Select

DuckDB is not just a query engine, it supports rich SQL that covers data transformation, creation, and some genuinely unique syntax extensions to available in most databases.

Full Suite of WINDOW Functions

Select
    customer,
    ordered_at,
    amount,

    -- Running total
    SUM(amount) OVER (PARTITION BY customer ORDER BY ordered_at) AS running_tot,

    -- Lag/lead comparisons
    LAG(amount) OVER (PARTITION BY customer ORDER BY ordered_at) AS prev_amt,

    -- Percentile rank
    PERCENT_RANK() OVER (ORDER BY amount) AS pct_rank,

    -- Named window reuse
    FIRST_VALUE(amount) OVER w AS first_order
FROM orders
WINDOW w AS (PARTITION BY customer ORDER BY ordered_at);

Enter fullscreen mode Exit fullscreen mode

DuckDB also allows the use of qualify clause which filters on window result without a subquery.

Select * From orders
QUALIFY ROW_NUMBER() OVER (PARTITION BY customer ORDER BY amount DESC) = 1;

Enter fullscreen mode Exit fullscreen mode

PIVOT and UNPIVOT

Most databases make you write case when manually for PIVOTS.
DuckDB does it natively.

--PIVOT- rows to columns
PIVOT orders on region USING SUM(amount) GROUP BY year;

--UNPIVOT- Column to rows
UNPIVOT sales_wide ON(q1,q2,q3,q4) INTO NAME quarter VALUE revenue;

Enter fullscreen mode Exit fullscreen mode

MULTI DATABASE SQL

--Attach another DuckDB file
ATTACH 'archive.duckdb' AS archive;

-- Cross-database join
SELECT a.*, b.region
FROM main.orders a
JOIN archive.customers b ON a.customer_id = b.id;

--Attach another database
ATTACH 'postgres://user:pass@host/db' AS pg (TYPE POSTGRES);
SELECT * FROM pg.public.users LIMIT 10;

Enter fullscreen mode Exit fullscreen mode

DUCKDB+Pandas+Polars --Choosing your stack

DuckDB does not replace pandas or Polars it solves a problem which is niche.The sweet spot of the industry is to use DuckDB for SQL-shaped operations and pandas/polars for row level python logic.

The Complimentary Trio

Where Duck DB shines

  1. Feature Engineering for ML: Window functions or group by's for feature computation are often faster and more readable in DuckDB then pandas before handing it over to Sklearn or pytorch

  2. Unit testing DBT models locally:DuckDB lets you run complete dbt project locally without a cloud warehouse providing fast feedback loop for data engineers.

  3. Light weight ETL Pipelines: One can read raw parquet from S3, transform with SQL, write cleaned output back without any spark cluster or airflow jobs.

Conclusion

DuckDB lets you think in SQL for analytical tasks without worrying about infrastructure setup. Anyone using python can utilize duckdb for analysis of larger files where regular pandas will give headache.
Given the advantages, it is important to know whare DuckDB should not be used which in case of concurrent writes,OLTP workloads and long running multi user services.

Reference-
https://duckdb.org/docs/current/data/overview