fasthtmlparser-pure 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: fasthtmlparser-pure
3
+ Version: 0.1.0
4
+ Summary: Fast HTML / XML parser for scraping with XPath 1.0 and CSS selectors, in pure Python. A port of z3l.FastHtmlParser.
5
+ Author: z3l
6
+ Project-URL: Homepage, https://github.com/romanti3172/fasthtmlparser-pure
7
+ Project-URL: Source, https://github.com/romanti3172/fasthtmlparser-pure
8
+ Project-URL: Issues, https://github.com/romanti3172/fasthtmlparser-pure/issues
9
+ Keywords: html,parser,xpath,css,selectors,scraping,web-scraping,pure-python
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: Other/Proprietary License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: Implementation :: CPython
16
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
17
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
18
+ Classifier: Topic :: Text Processing :: Markup :: HTML
19
+ Classifier: Topic :: Text Processing :: Markup :: XML
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE.md
24
+ Dynamic: license-file
25
+
26
+ # fasthtmlparser-pure
27
+
28
+ [![CI](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml/badge.svg)](https://github.com/romanti3172/fasthtmlparser-pure/actions/workflows/ci.yml)
29
+
30
+ A fast HTML / XML parser for scraping, with **XPath 1.0** and **CSS selectors**, in **pure Python**: a port of
31
+ [z3l.FastHtmlParser](https://github.com/romanti3172/z3l.FastHtmlParser) with no compiled code and no dependencies. It
32
+ is built for extracting data, not for building a DOM: a page becomes a flat list of tags that hold only positions in
33
+ the source; text, attributes and entities are read when you ask for them.
34
+
35
+ It is **9x faster than BeautifulSoup with html.parser** (the other pure-Python option) and scrapes about as fast as
36
+ lxml, which is C. Where you can install compiled wheels, the Rust-backed
37
+ [`fasthtmlparser`](https://github.com/romanti3172/fasthtmlparser-py) is another 20x faster with **the same API**; this
38
+ package is for the places where you cannot: PyPy, Pyodide / the browser, restricted or embedded interpreters,
39
+ platforms without wheels, vendoring a single folder.
40
+
41
+ ```
42
+ pip install fasthtmlparser-pure
43
+ ```
44
+
45
+ Python 3.10 or later, CPython or PyPy; no dependencies.
46
+
47
+ ```python
48
+ import fasthtmlparser_pure as fh
49
+
50
+ doc = fh.parse(html, url="https://books.toscrape.com/") # str or bytes; url resolves relative links
51
+
52
+ # CSS selectors, as querySelectorAll / querySelector
53
+ for pod in doc.css("article.product_pod"):
54
+ title = pod.css_first("h3 a").attr("title")
55
+ price = pod.css_first("p.price_color").text
56
+ link = pod.css_first("h3 a").href # absolute URL
57
+ ul.css("> li") # the children of ul
58
+
59
+ # XPath 1.0
60
+ doc.xpath("//div[@class='card']//span[@class='price']") # tags
61
+ doc.xpath_values("//a[contains(@href, '/product/')]/@href")
62
+ doc.xpath_value("//dt[.='Price']/following-sibling::dd[1]")
63
+ doc.xpath_value("count(//table//tr)") # "12"
64
+
65
+ # compile once, reuse on any number of pages and threads
66
+ TITLES = fh.XPathQuery("//article//h3/a/@title")
67
+ TITLES.values(doc)
68
+ PRICES = fh.CssQuery("p.price_color")
69
+ PRICES.all(doc)
70
+
71
+ # search by name (any name, case-insensitive) and criteria, as in BeautifulSoup
72
+ pod = doc.find("article", class_="product_pod")
73
+ pod.find("p", class_="price_color").text
74
+ doc.find_all("a", attr=("rel", "next"))
75
+ doc.find("dt", text="Price").find_next_sibling("dd").text
76
+ doc.find("my-widget", id_starts_with="w-")
77
+ # criteria: class_, id, attr=(name, value), text, id_starts_with, text_starts_with, body, body_starts_with, source
78
+
79
+ # reading a tag
80
+ tag.name, tag.depth, tag.index, tag.pos # pos: byte offsets in the UTF-8 source
81
+ tag.text # visible text, entities decoded, whitespace collapsed
82
+ tag.text_line_breaks # <br> and block elements -> new lines, <p> and headings -> paragraphs
83
+ tag.attr("data-src") # decoded value, "" when missing; attr_raw(): as written
84
+ tag.attrs # {"href": "...", "class": "..."}
85
+ tag.href, tag.src # absolute URLs; href_from(base) / src_from(base)
86
+ tag.mailto, tag.tel # the address of a mailto: link, the number of a tel: link
87
+ tag.body, tag.outer_html, tag.source # inner HTML, the whole element, the opening tag
88
+
89
+ # navigation
90
+ tag.parent, tag.children, tag.next_sibling, tag.previous_sibling, tag.next, tag.previous
91
+ tag.find_parent("table"), tag.find_next("h2"), tag.text_after_until("br")
92
+
93
+ # the whole document
94
+ len(doc), doc[0], doc[-1], list(doc) # every tag, comments included
95
+ ```
96
+
97
+ To use the Rust package where it is installed and this one elsewhere:
98
+
99
+ ```python
100
+ try:
101
+ import fasthtmlparser as fh
102
+ except ImportError:
103
+ import fasthtmlparser_pure as fh
104
+ ```
105
+
106
+ A missing tag is `None`, a missing value is `""`. An invalid selector raises `fh.CssSelectorError`, an invalid XPath
107
+ expression `fh.XPathError` (both are `ValueError`s); `xpath()` on an expression that gives a number or string raises
108
+ `XPathError` too (use `xpath_value`). The string methods compile and cache queries. A `Node` keeps its document alive,
109
+ nodes compare equal when they are the same tag, and are hashable. Documents and compiled queries are read-only and can
110
+ be shared between threads. Type stubs are included.
111
+
112
+ CSS: type, `*`, `#id`, `.class`, attribute selectors with all operators and the `i` / `s` flags, the four combinators,
113
+ selector lists, `:first-child`, `:last-child`, `:only-child`, `:*-of-type`, `:nth-child(An+B [of S])` and its relatives,
114
+ `:not()`, `:is()`, `:where()`, `:has()`, `:empty`, `:root`, `:scope`, `:link`, `:checked`, `:disabled`, `:enabled`,
115
+ `:required`, `:optional`, `:contains("text")`. XPath: all axes except namespace, predicates, `|`, the operators and all
116
+ XPath 1.0 functions, plus `ends-with()`, `lower-case()`, `upper-case()`. HTML rules apply: names are case-insensitive,
117
+ the string-value of an element is its visible text, attribute values and text are decoded. HTML5 optional end tags
118
+ (`<li>`, `<p>`, `<td>`, `<option>` without end tags) give the same elements as in a browser; there is no full HTML5
119
+ tree construction (no implied `<tbody>` or `<html>`), and documents are read-only.
120
+
121
+ ## Same results as the .NET version
122
+
123
+ `tests/test_conformance.py` runs the conformance data of the other ports: on 117 pages (fixtures, broken markup,
124
+ cut-off pages, CR LF, 600-deep nesting, ...) every tag's name, position, text, text with line breaks, attributes,
125
+ navigation and links, and 569 XPath / CSS queries on the document and from three tags of each page, must give exactly
126
+ what z3l.FastHtmlParser (.NET) gives. `tests/test_api.py` is the test suite of the Rust-backed package, unchanged.
127
+
128
+ ## Benchmarks
129
+
130
+ `python bench/bench.py` (Python 3.14, AMD Ryzen 7 3800X, Windows; [`bench-results.md`](https://github.com/romanti3172/fasthtmlparser-pure/blob/main/bench-results.md)). Every
131
+ library must extract the same records before anything is timed. The first two columns are pure Python; the others are
132
+ C or Rust, for reference.
133
+
134
+ Parse a page:
135
+
136
+ | Page | fasthtmlparser-pure | BeautifulSoup (html.parser) | lxml | selectolax (lexbor) | fasthtmlparser (Rust) |
137
+ |---|---:|---:|---:|---:|---:|
138
+ | quotes, 11 KB | 577 μs | 5,488 μs | 486 μs | 96 μs | 21 μs |
139
+ | laptops, 38 KB | 1,724 μs | 15,287 μs | 1,554 μs | 349 μs | 67 μs |
140
+ | books, 51 KB | 2,081 μs | 18,907 μs | 1,563 μs | 309 μs | 70 μs |
141
+ | books x10, 510 KB | 19,792 μs | 188,407 μs | 15,169 μs | 3,417 μs | 727 μs |
142
+ | books without `</li>` `</p>` | 2,839 μs | 17,465 μs | 1,511 μs | 231 μs | 70 μs |
143
+
144
+ Scrape a page: parse and extract the records (books: 20 × title, price, rating; quotes: 10 × text, author, tags).
145
+
146
+ | Task | fasthtmlparser-pure | BeautifulSoup (html.parser) | lxml / parsel | selectolax | fasthtmlparser (Rust) |
147
+ |---|---:|---:|---:|---:|---:|
148
+ | 20 books, `find` | 2,610 μs | | | | 138 μs |
149
+ | 20 books, CSS | 2,827 μs | 22,535 μs | parsel 2,552 μs | 579 μs | |
150
+ | 20 books, XPath | 3,906 μs | | lxml 2,778 μs | | |
151
+ | 10 quotes | 949 μs | 6,770 μs | parsel 1,057 μs | 282 μs | 66 μs |
152
+
153
+ ## Development
154
+
155
+ ```
156
+ python -m venv .venv && .venv/Scripts/activate # or . .venv/bin/activate
157
+ pip install -e . pytest
158
+ python -m pytest
159
+ ```
160
+
161
+ `tools/gen.py` rebuilds the tag list and the HTML5 entity table (`fasthtmlparser_pure/_tables.py`) from the C# sources.
162
+
163
+ ## License
164
+
165
+ Same terms as z3l.FastHtmlParser (see LICENSE.md): free for companies under USD 1M annual revenue and under 100
166
+ people, a commercial license above that. This is source-available, not an OSI open-source license.
@@ -0,0 +1,19 @@
1
+ fasthtmlparser_pure/__init__.py,sha256=Z1uTG6RJzHqMbaZH9NHu_CUQQ1kFRh64IP0_uNejUgg,992
2
+ fasthtmlparser_pure/_api.py,sha256=1td9H_hyQsygs0Ji_1P7h7staT9203f5_aHXfnZqfGY,22185
3
+ fasthtmlparser_pure/_api.pyi,sha256=9tTFTJI7bJzlMmVxLLE8EZAsKxq3EmSwD6iStgtUcJ0,13880
4
+ fasthtmlparser_pure/_attrs.py,sha256=OFlve1ZShMFRYBcKEUKMFYgXJxHAbkZ-FyyyBcuZuJw,9196
5
+ fasthtmlparser_pure/_chars.py,sha256=OdxIftKpq_VvDs3XbpV1Hed1Gwa4p8uAzoXFPTJcX28,3622
6
+ fasthtmlparser_pure/_css.py,sha256=wk9jYNERLR5XsnhzyHPm_govfC6KfAIlP8Kn-CyV1xo,29505
7
+ fasthtmlparser_pure/_decode.py,sha256=b7ZlTTi9JeKs6Y7vlA8Fko_-miKzyxUlwu8-nNP378M,4784
8
+ fasthtmlparser_pure/_links.py,sha256=1mz6GQmtwnQ0r8YfzdQ8V8F20QB25iq6Pie9ZcISTw0,14317
9
+ fasthtmlparser_pure/_parser.py,sha256=LFtRhgp1w-MU0XfGa1_zj5ZzCId7tNgL8l9vaHQyAQY,35948
10
+ fasthtmlparser_pure/_query.py,sha256=kzwhDDz0mFAKr3bJ7wtALXlLBx1Gk2dfGFxcto-k1LY,5148
11
+ fasthtmlparser_pure/_tables.py,sha256=EF4admsa8VYJXUZzGyIvrP0NHcx87MTu5c7-WSf8RJ8,57934
12
+ fasthtmlparser_pure/_text.py,sha256=nPFqrxsGGSq6NhtEie59lCdiigMOMUxJthTUjvPUu88,8963
13
+ fasthtmlparser_pure/_xpath.py,sha256=PQuSK60sG7ce9Vz7ZFcwRkU9GbKE8WpPa3l3WnotJFk,57349
14
+ fasthtmlparser_pure/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ fasthtmlparser_pure-0.1.0.dist-info/licenses/LICENSE.md,sha256=cgUxPcmlgTJLozMhaEhbdIMyTejARjcn21bRsLE_jno,4012
16
+ fasthtmlparser_pure-0.1.0.dist-info/METADATA,sha256=ORcCci6AlarWseXQPFzDd5uilQEb_5cSLifiGUeHtBk,8622
17
+ fasthtmlparser_pure-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
18
+ fasthtmlparser_pure-0.1.0.dist-info/top_level.txt,sha256=TRfytbGARu9B-rgQZg73my7qVR6yjkZw7RcvFGgMwtA,20
19
+ fasthtmlparser_pure-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,79 @@
1
+ # z3l.FastHtmlParser License
2
+
3
+ Copyright © 2026 z3l. All rights reserved.
4
+
5
+ This license applies to the z3l.FastHtmlParser library, its source code, binaries and
6
+ NuGet packages (the "Software").
7
+
8
+ ## 1. Definitions
9
+
10
+ - **"Licensee"** — the individual or legal entity that uses the Software, together with its
11
+ Affiliates.
12
+ - **"Affiliate"** — any entity that controls, is controlled by, or is under common control with
13
+ the Licensee.
14
+ - **"Annual Revenue"** — the total gross revenue of the Licensee (including all Affiliates) for
15
+ the last completed fiscal year, in US dollars or equivalent.
16
+ - **"Headcount"** — the total number of employees and individual contractors working for the
17
+ Licensee (including all Affiliates) on a full-time or full-time-equivalent basis, at any time
18
+ during the last 12 months.
19
+ - **"Small Licensee"** — a Licensee whose Annual Revenue is **below USD 1,000,000** and whose
20
+ Headcount is **below 100**. Both conditions must be met.
21
+
22
+ ## 2. Free License (Small Licensees)
23
+
24
+ If the Licensee is a Small Licensee (Annual Revenue **below USD 1,000,000** and Headcount
25
+ **below 100**), the Licensee is granted, free of charge, a worldwide, non-exclusive,
26
+ non-transferable license to use, copy and modify the Software and to distribute it as part of the
27
+ Licensee's own applications and services, including commercial ones.
28
+
29
+ ## 3. Commercial License (all other Licensees)
30
+
31
+ If the Licensee's Annual Revenue is **USD 1,000,000 or more**, or its Headcount is **100 or
32
+ more**, the Licensee must purchase a Commercial License.
33
+
34
+ - Price: a **one-time payment of USD 1,000** per Licensee (the Licensee together with all its
35
+ Affiliates).
36
+ - The Commercial License is perpetual and covers all current and future versions of the
37
+ Software, any number of developers, applications, servers and deployments of the Licensee.
38
+ - A Licensee that stops being a Small Licensee (its Annual Revenue or Headcount reaches the
39
+ threshold) while already using the Software must purchase the Commercial License within
40
+ 30 days.
41
+ - To purchase: https://romanti3172.github.io/z3l.FastHtmlParser/#pricing, or contact **romanti3172@gmail.com** for an invoice.
42
+
43
+ The Commercial License grants the same rights as section 2, without the revenue and headcount
44
+ limits.
45
+
46
+ **One license for all z3l libraries.** The Commercial License is not limited to the Software: it
47
+ also covers z3l.Scraper and every other library and package published by z3l, now or in the
48
+ future, on the same terms. The Licensee pays USD 1,000 once and needs no other z3l license.
49
+
50
+ ## 4. Conditions (both licenses)
51
+
52
+ 1. This license text and the copyright notice must be kept in all copies or substantial portions
53
+ of the Software's source code.
54
+ 2. The Licensee may not sell, sublicense or redistribute the Software on its own, or as part of a
55
+ library, SDK or component whose main purpose is HTML/XML parsing, so that it competes with the
56
+ Software.
57
+ 3. Modified versions of the Software may not be published or distributed under a different
58
+ license.
59
+ 4. End users of the Licensee's applications and services do not need their own license to use
60
+ those applications and services.
61
+
62
+ ## 5. Termination
63
+
64
+ The license terminates automatically if the Licensee breaches it and does not cure the breach
65
+ within 30 days after becoming aware of it. On termination the Licensee must stop using and
66
+ distributing the Software.
67
+
68
+ ## 6. No Warranty
69
+
70
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
71
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
72
+ NONINFRINGEMENT.
73
+
74
+ ## 7. Limitation of Liability
75
+
76
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
78
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE TOTAL LIABILITY OF
79
+ THE COPYRIGHT HOLDERS SHALL NOT EXCEED THE AMOUNT PAID BY THE LICENSEE FOR THE SOFTWARE.
@@ -0,0 +1 @@
1
+ fasthtmlparser_pure