Python wrapper for html_transpose - a Rust library for transposing HTML tables
Project description
html_transpose
Python wrapper for html_transpose - a Rust library for transposing HTML tables while preserving merged cells, attributes, and structure.
Features
- ✅ Table Transposition: Swaps rows and columns of HTML tables
- ✅ Merged Cell Support: Correctly handles
rowspanandcolspanattributes - ✅ Attribute Preservation: Maintains all attributes on both table and cell elements
- ✅ HTML Escaping: Properly escapes HTML special characters
- ✅ Error Handling: Returns descriptive errors for invalid input
- ✅ High Performance: Built with Rust for speed
Installation
Using uv
uv pip install html_transpose
Using pip
pip install html_transpose
From source
# Clone the repository
git clone https://github.com/snurf198/html_transpose_py.git
cd html_transpose_py
# Install using uv
uv pip install -e .
# Or using pip
pip install -e .
Usage
import html_transpose
# Simple table transpose
html_table = """
<table>
<tr><td>A</td><td>B</td></tr>
<tr><td>C</td><td>D</td></tr>
</table>
"""
transposed = html_transpose.transpose(html_table)
print(transposed)
# Output:
# <table>
# <tr><td>A</td><td>C</td></tr>
# <tr><td>B</td><td>D</td></tr>
# </table>
Handling Merged Cells
The library correctly handles tables with rowspan and colspan:
html_table = """
<table>
<tr>
<td rowspan="2">A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
</tr>
</table>
"""
transposed = html_transpose.transpose(html_table)
# The rowspan becomes colspan in the transposed table
Error Handling
import html_transpose
try:
result = html_transpose.transpose("<div>Not a table</div>")
except ValueError as e:
print(f"Error: {e}")
API Reference
transpose(html: str) -> str
Transposes an HTML table string.
Parameters:
html(str): A string containing an HTML table (must contain a<table>element)
Returns:
str: The transposed HTML table as a string
Raises:
ValueError: If no<table>element is found in the input or if the HTML parser fails
Requirements
- Python 3.8+
- Rust (for building from source)
Development
Setting up the development environment
# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv pip install -e ".[dev]"
# Or using pip
pip install -e ".[dev]"
Building
This package uses maturin to build the Rust extension:
# Install maturin
pip install maturin
# Build in development mode
maturin develop
# Build for distribution
maturin build
Running tests
# Using pytest
pytest
# Or using Python unittest
python -m unittest discover
License
This project is available under the MIT License.
Credits
- Original Rust library: html_transpose
- Built with PyO3 and maturin
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
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 html_transpose-0.0.6.tar.gz.
File metadata
- Download URL: html_transpose-0.0.6.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3b298a3e8f05904b2736ae62a4772650c18ad881505fa217c55cb1212ee19e0
|
|
| MD5 |
2fe7ea9a520386aee833f422ade327ec
|
|
| BLAKE2b-256 |
be9355aea125e7b8e5711052a1ceab0401f88afe8b478e835bd36b5dc0d77c92
|
File details
Details for the file html_transpose-0.0.6-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: html_transpose-0.0.6-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 520.4 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8ef2ffcd1b227165841213bc6020d9ebf0447547b4b7bb8b374083984e3b345
|
|
| MD5 |
f66aa29b2c1562f0eecf9b2b619082c7
|
|
| BLAKE2b-256 |
f52b05b5b0ef281df47c1ab235d8ba342eea7142b482b19f9d22d5ca7b6a01ed
|