Skip to main content

A high-performance CLI tool to convert local data science workspaces into LLM-ready context.

Project description

Data2Prompt Banner

PyPI version License Python 3.10+ Status

High-performance codebase-to-prompt orchestration for Data Science workflows and data-heavy projects.

data2prompt is a CLI tool designed to bridge the gap between local data-heavy projects and Large Language Model (LLM) context windows. Unlike generic code-packagers, it provides an intelligent,optimized output for LLM attention mechanism, token-aware representation of a project's structure and content.

📝 Important Note

Data2prompt is purpose-built for data-heavy projects (.csv, .sql, .xlsx, .ipynb), not large pure-code repositories. It intelligently samples and truncates data files to prevent context window explosion while preserving semantic structure.

🎯 Why Data2Prompt?

Generic code-to-prompt tools choke on data files—they either skip them entirely or dump raw CSVs that waste 90% of your context window. Data2Prompt solves this with intelligent sampling, schema extraction, and LLM-optimized formatting specifically designed for data science workflows.

Data2Prompt Comparison

✨ Core Features

  • Smart Jupyter Parsing: Intelligently extracts code, markdown, and text outputs from .ipynb files while stripping heavy Base64 images and raw HTML to preserve context.
  • Multi-Format Sampling: Advanced sampling strategies for CSV, SQL, and Excel files to preserve schema and data context which reduces the data size significantly while extracting the needed context for llm.
  • Stats-Aware Metadata: Each table is annotated with a metadata block — column dtypes, missing counts/percentages, and a describe() summary — all computed on the full dataset (not the sample), so the LLM sees true data quality. Toggle with --no-stats-summary.
  • Secret-Safe .env Handling: .env files are surfaced as variable names with redacted values (KEY=<redacted>) so the LLM understands the project's configuration without ever leaking secrets. Disable with --no-env-keys.
  • Direct Clipboard Output: --clipboard copies the generated prompt straight to your system clipboard (no file), using native OS tools with a graceful file fallback.
  • Aggressive truncations: To preserve context, long lines are truncated to neutralize line injections and avoid exploding the context windows, if a tabular data was still to large after sampling it will get truncated to a certain amount, also if a raw text file of unhandled type was too large it will get truncated to a certain amount.
  • Defensive Processing: Automatic binary detection (Null-byte checks), Checks if a file is binary by looking for a Null byte in the first 1024 bytes.
  • Optimized LLM attention: The default output format is markdown with well structured schema and another option is xml output with xml style tags to enhance LLM anchoring for complex analysis and large context windows
  • Token-Aware Output: Real-time token estimation using tiktoken (o200k_base) to ensure prompts fit target LLMs (Claude 3.5, GPT-4o, Gemini 1.5) and advanced offline token counting via regex.
  • Professional TUI: A high-fidelity terminal interface built with Rich, featuring a Matrix-style startup animation and interactive, scrollable reports on Windows.
  • Dynamic Markdown Wrapping: Uses intelligent backtick depth to ensure robust nesting of code blocks in the final output.
  • Gitignore aware: Respects the .gitignore rules by default and you can turn this feature off with cli argument(--no-gitignore) if needed.

🏗️ Architecture

The codebase is organized into small, single-responsibility modules — parsing, output generation, scanning, and UI are kept separate so each can be tested and extended on its own:

  • Registry & Strategy Patterns: A ParserRegistry handles extensible file parsing and an OutputGenerator strategy supports multiple output formats (Markdown, XML).
  • Centralized Configuration: Core logic, magic numbers, and default ignore lists live in one place: src/data2prompt/constants.py.
  • Strict Type Hinting: Fully typed function signatures (PEP 484) across all modules.
  • UI Encapsulation: Terminal feedback is handled by a dedicated UIHandler, keeping presentation separate from logic.

For a deep dive into the module layout and data flow, see the Architecture Documentation.

🚀 Quick Start

Installation

Ensure you have Python 3.10+ installed.

Recommended — using pipx (installs as a global CLI tool):

Don't have pipx? Install it first:

pip install pipx
pipx ensurepath

Then install data2prompt:

pipx install data2prompt

Alternative — using pip (requires an active virtual environment):

pip install data2prompt

Update to the latest version:

# with pipx
pipx upgrade data2prompt

# with pip
pip install --upgrade data2prompt

Install from the source

# Clone the repository
git clone https://github.com/arianmokhtariha/data2prompt.git
cd data2prompt

# Install normally
pip install .

# Or Install in editable mode
pip install -e .

Optional: Parquet, Feather, and Arrow support

Support for .parquet, .feather, and .arrow files requires pyarrow, which is not bundled by default. Choose the command that matches how you installed data2prompt:

Scenario Command
pip — fresh install pip install data2prompt[parquet]
pip — already installed pip install pyarrow
pipx — fresh install pipx install data2prompt[parquet]
pipx — already installed pipx inject data2prompt pyarrow

If pyarrow is not installed, these files still appear in the output with a short inline note explaining why they were skipped.

Usage

Run data2prompt in your project root to generate a structured prompt:

# Basic usage (defaults to markdown output)
data2prompt

# Custom output with xml format and specific sampling
data2prompt --output my_analysis --format xml --csv-sample-size 50 --ignore-folders venv .pytest_cache

CLI Arguments

Argument Description Default
-o, --output Base name of the generated file PROMPT
-f, --format Output format (xml or markdown) markdown
-s, --csv-sample-size Number of random rows to sample from CSVs 15
--max-lines Max lines of text output per notebook cell 40
--max-file-size Max file size in KB to read entirely 70
-c, --clipboard Copy the output to the system clipboard instead of writing a file off
--schema-only Emit only the schema (columns + dtypes) of data files, no rows off
--no-stats-summary Disable the per-table stats block (dtypes, missing %, describe()) on
--no-env-keys Skip .env files entirely instead of listing redacted variable names on

See the CLI Reference for a full list of arguments.

📚 Documentation

Explore the detailed documentation for more information:

🛠️ Developer Setup

To contribute or run tests:

pip install -e .[dev]
pytest

🌟 Show Your Support

If Data2Prompt saves you token costs or speeds up your workflow, consider:

  • ⭐ Starring the repo
  • 🐛 Reporting issues or suggesting features
  • 🔀 Contributing parsers for new file types

Star History

Star History Chart

Built for the modern AI-assisted development workflow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

data2prompt-0.4.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

data2prompt-0.4.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file data2prompt-0.4.0.tar.gz.

File metadata

  • Download URL: data2prompt-0.4.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for data2prompt-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6912b0b240bfac6554691b683e544b5dce690c7c0df0dabcf5bddad7687b8155
MD5 86e45085021d6ebc42ff8c8d795e6151
BLAKE2b-256 e284496dc43dde120af58448a51139c267f3029cb2054d43337e14a710ce2df9

See more details on using hashes here.

File details

Details for the file data2prompt-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: data2prompt-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for data2prompt-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18aa55e393b1ff36ffbc3d31679453a57bc1a5cfff6d1242afad6c5843336087
MD5 86e3307b85ffebc5e164d83df54dcc99
BLAKE2b-256 b57e840f9e16443125205610d1131c74ff6e9f14a72d8a171113953fbfef701c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page