StruFi: HTTP Structured Field Values
This library implements a parser and a serializer for RFC 9651 (HTTP Structured Field Values).
Installation
Install strufi by running pip install strufi.
strufi package has no dependency.
See also package page on PyPI.
Usage
Parser
strufi module exposes 3 functions to parse structured field values:
load_itemto parse a single item, returning the value with the parameters.>>> import strufi >>> strufi.load_item('text/html; charset=utf-8') ('text/html', {'charset': 'utf-8'})
load_listto parse a list of items, returning a list of pairs (value, parameters).>>> strufi.load_list('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') [('text/html', {}), ('application/xhtml+xml', {}), ('application/xml', {'q': 0.9}), ('*/*', {'q': 0.8})]
load_dictto parse a map of keys:items, returning values with their parameters.>>> strufi.load_dict('u=1, i') {'u': (1, {}), 'i': (True, {})}
Serializer
The module also exposes functions for the serializing operations, which are the reverse operations of the parsing ones.
dump_itemtakes a value with parameters and returns the structured field value representation of a single item as a string>>> strufi.dump_item(('text/html', {'charset': 'utf-8'})) '"text/html";charset="utf-8"'
dump_listtakes a list of items and return the structured list representation>>> strufi.dump_list([('text/html', {}), ('application/xhtml+xml', {}), ('application/xml', {'q': 0.9}), ('*/*', {'q': 0.8})]) '"text/html", "application/xhtml+xml", "application/xml";q=0.9, "*/*";q=0.8'
dump_dicttakes a dictionnary of key:item and return the structured dict representation>>> strufi.dump_dict({'u': (1, {}), 'i': (True, {})}) 'u=1, i'
Development
Environment
Use pip install -e '.[dev]' to install strufi with development dependencies (tests & lint) in your local (virtual) environment.
Here are the tools you can use to reproduce the checks made by the continuous integration workflow:
ruff format --diffto check file format (you can runruff formatto apply changes)ruff checkto check for specific linting rulesmypy .to check for type annotations consistencypytest -vvto run tests suit
All these commands are also available through a Makefile that also takes care of the virtual environment: make lint, make mypy and make tests.
You could also run make all or simply make to execute the three tasks.
Contributing
Feel free to open issues to report bugs or ask for features and to open pull-requests to work on existing issues.
The code of the project is published under MIT license.
Packaging
Build dependencies can be installed with pip install -e '.[build]'.
Then the package can be built with python -m build (or make build) and uploaded on PyPI with twine upload dist/* (or make upload that builds & uploads the package).
Metadata
Release files for strufi 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strufi-1.0.1.tar.gz | 15.2 kB | Without provenance | Details for strufi-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strufi-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for strufi-1.0.1-py3-none-any.whl |
Total release size: 24.6 kB
Release files / strufi-1.0.1.tar.gz
| Download URL | strufi-1.0.1.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d13fcb0fc84c64a630af7c7847febd6da4479005f2a209d9a01a8faf48296a7e
|
|
BLAKE2b-256 checksum How to use checksums |
146e54072116d589f1ce5275be3805823ee14cdcfad9e71dff109c8a97aef495
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / strufi-1.0.1-py3-none-any.whl
| Download URL | strufi-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0559daeed00a084349d718ba7ba279086d2d80e577a0587c53961898663a7d55
|
|
BLAKE2b-256 checksum How to use checksums |
ea35c9f98021009216ed30224299e6cde399491be6ab5545a30d0d57f98f6543
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for strufi 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.