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
- datapasta checks if the
cliptargetspackage is available - If available, it looks for the
text/htmltarget in the clipboard - If HTML content is found, it extracts tables using a lightweight HTML parser
- It detects headers based on HTML structure (
<thead>or<th>elements) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e19fc3395e919da6d1dc855422aed0385d8eeec7f57c5fc49776fffa77a2ae7
|
|
| MD5 |
df82b281cb7b4f8d0a15420ca884da2c
|
|
| BLAKE2b-256 |
dc12972517ee34bb9c607bc68722ae45b39f7deccb7e73da5bc9b7894e265170
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e872f3a2c448800af460ffe275a0c5c5cf1ead9b172c85867ecc0ff9c82e21fb
|
|
| MD5 |
9722859a2fa7fa8055e4e0bd10e5e0c1
|
|
| BLAKE2b-256 |
87186e1be3372af8020f07614db1e1427a595efa4155d324489853f31358ced9
|