
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
djc-core-html-parser
Advanced tools
HTML parser used by django-components. Written in Rust, exposed as a Python package with maturin.
This implementation was found to be 40-50x faster than our Python implementation, taking ~90ms to parse 5 MB of HTML.
pip install djc-core-html-parser
from djc_core_html_parser import set_html_attributes
html = '<div><p>Hello</p></div>'
result, _ = set_html_attributes(
html,
# Add attributes to the root elements
root_attributes=['data-root-id'],
# Add attributes to all elements
all_attributes=['data-v-123'],
)
To save ourselves from re-parsing the HTML, set_html_attributes
returns not just the transformed HTML, but also a dictionary as the second item.
This dictionary contains a record of which HTML attributes were written to which elemenents.
To populate this dictionary, you need set watch_on_attribute
to an attribute name.
Then, during the HTML transformation, we check each element for this attribute. And if the element HAS this attribute, we:
from djc_core_html_parser import set_html_attributes
html = """
<div data-watch-id="123">
<p data-watch-id="456">
Hello
</p>
</div>
"""
result, captured = set_html_attributes(
html,
# Add attributes to the root elements
root_attributes=['data-root-id'],
# Add attributes to all elements
all_attributes=['data-djc-tag'],
# Watch for this attribute on elements
watch_on_attribute='data-watch-id',
)
print(captured)
# {
# '123': ['data-root-id', 'data-djc-tag'],
# '456': ['data-djc-tag'],
# }
Setup python env
python -m venv .venv
Install dependencies
pip install -r requirements-dev.txt
The dev requirements also include maturin
which is used packaging a Rust project
as Python package.
Install Rust
Run Rust tests
cargo test
Build the Python package
maturin develop
To build the production-optimized package, use maturin develop --release
.
Run Python tests
pytest
NOTE: When running Python tests, you need to run
maturin develop
first.
Deployment is done automatically via GitHub Actions.
To publish a new version of the package, you need to:
pyproject.toml
and Cargo.toml
main
.main
branch with the new version number (e.g. v1.0.0
), or create a new release in the GitHub UI.FAQs
HTML parser used by django-components written in Rust.
We found that djc-core-html-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.