Skip to main content

Paste data as Python DataFrame definitions

Project description

Enhanced HTML Table Support

When the cliptargets package is installed, datapasta gains the ability to extract tables directly from HTML content in the clipboard. This is especially useful when copying tables from web pages, spreadsheets, or other applications that place HTML content in the clipboard.

Installation with HTML Table Support

# Install with HTML table support via cliptargets
pip install "datapasta[targets]"

# For complete installation (pandas, polars, and HTML support)
pip install "datapasta[full]"

Benefits of HTML Table Support

  • Improved Header Detection: Automatically detects table headers based on HTML structure (<thead> or <th> elements)
  • Better Structure Preservation: Extracts data directly from HTML table structure, preserving rows and columns correctly
  • No Delimiter Issues: Avoids problems with delimiter guessing and text parsing
  • Works with Web Content: Ideal for copying tables from websites and web applications

Using with HTML Tables

The API remains the same - datapasta automatically detects if HTML content is available in the clipboard and uses it when appropriate:

import datapasta

# Will automatically use HTML table content if available
code = datapasta.clipboard_with_targets_to_pandas()
print(code)

GitHub Artifacts example

If you go to the GitHub Actions results summary page you see a HTML table. datapasta will generate the DataFrame code for you from the clipboard :magic_wand:

(datapasta) louis ๐Ÿšถ ~/dev/datapasta $ datapasta --polars
import polars as pl

df = pl.DataFrame({
    'Name': ['wheels-linux-aarch64', 'wheels-linux-armv7', 'wheels-linux-ppc64le',
'wheels-linux-s390x'],
    'Size': ['4.2 MB', '3.78 MB', '4.63 MB', '5.5 MB'],
})
(datapasta) louis ๐Ÿšถ ~/dev/datapasta $ python -ic "$(datapasta --polars)"
>>> print(df)
shape: (4, 2)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Name                 โ”† Size    โ”‚
โ”‚ ---                  โ”† ---     โ”‚
โ”‚ str                  โ”† str     โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚ wheels-linux-aarch64 โ”† 4.2 MB  โ”‚
โ”‚ wheels-linux-armv7   โ”† 3.78 MB โ”‚
โ”‚ wheels-linux-ppc64le โ”† 4.63 MB โ”‚
โ”‚ wheels-linux-s390x   โ”† 5.5 MB  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Command Line Usage

# Automatically uses HTML table content if available
datapasta

# Force using legacy clipboard access (no HTML support)
datapasta --legacy

How It Works

  1. datapasta checks if the cliptargets package is available
  2. If available, it looks for the text/html target in the clipboard
  3. If HTML content is found, it extracts tables using a lightweight HTML parser
  4. It detects headers based on HTML structure (<thead> or <th> elements)
  5. If no HTML content is found or no tables are present, it falls back to the text-based parsing

This feature is particularly useful when copying tables from web applications, where the HTML structure provides more reliable information about the table's layout and headers than plain text.

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

datapasta-0.1.2.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

datapasta-0.1.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file datapasta-0.1.2.tar.gz.

File metadata

  • Download URL: datapasta-0.1.2.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.12.6 Linux/5.15.0-125-generic

File hashes

Hashes for datapasta-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6e19fc3395e919da6d1dc855422aed0385d8eeec7f57c5fc49776fffa77a2ae7
MD5 df82b281cb7b4f8d0a15420ca884da2c
BLAKE2b-256 dc12972517ee34bb9c607bc68722ae45b39f7deccb7e73da5bc9b7894e265170

See more details on using hashes here.

File details

Details for the file datapasta-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: datapasta-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.12.6 Linux/5.15.0-125-generic

File hashes

Hashes for datapasta-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e872f3a2c448800af460ffe275a0c5c5cf1ead9b172c85867ecc0ff9c82e21fb
MD5 9722859a2fa7fa8055e4e0bd10e5e0c1
BLAKE2b-256 87186e1be3372af8020f07614db1e1427a595efa4155d324489853f31358ced9

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