strufi


Namestrufi JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryParser for HTTP Structured Field Values
upload_time2025-07-10 14:23:45
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseNone
keywords http structured field values rfc 8941 rfc 9651
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # StruFi: HTTP Structured Field Values

This library implements a parser and a serializer for [RFC 9651](https://www.rfc-editor.org/rfc/rfc9651.html) (HTTP Structured Field Values).


## Installation

Install `strufi` by running `pip install git+https://github.com/alma/strufi.git`
`strufi` package has no dependency.


## Usage

### Parser

`strufi` module exposes 3 functions to parse structured field values:

- `load_item` to parse a single item, returning the value with the parameters.
    ```pycon
    >>> import strufi
    >>> strufi.load_item('text/html; charset=utf-8')
    ('text/html', {'charset': 'utf-8'})
    ```
- `load_list` to parse a list of items, returning a list of pairs (value, parameters).
    ```pycon
    >>> 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_dict` to parse a map of keys:items, returning values with their parameters.
    ```pycon
    >>> 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_item` takes a value with parameters and returns the structured field value representation of a single item as a string
    ```pycon
    >>> strufi.dump_item(('text/html', {'charset': 'utf-8'}))
    '"text/html";charset="utf-8"'
    ```
- `dump_list` takes a list of items and return the structured list representation
    ```pycon
    >>> 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_dict` takes a dictionnary of key:item and return the structured dict representation
    ```pycon
    >>> 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 --diff` to check file format (you can run `ruff format` to apply changes)
- `ruff check` to check for specific linting rules
- `mypy .` to check for type annotations consistency
- `pytest -vv` to 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](https://github.com/alma/strufi/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](https://github.com/alma/strufi/blob/main/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](https://pypi.org/project/strufi/) with `twine upload dist/*` (or `make upload` that builds & uploads the package).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "strufi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "HTTP, Structured Field Values, RFC 8941, RFC 9651",
    "author": null,
    "author_email": "Alma Engineering <engineering@almapay.com>",
    "download_url": "https://files.pythonhosted.org/packages/cf/de/3d412197e1d33e36f521d0fb0ebdec2b1211606554ed653fc82e1d589b9a/strufi-1.0.0.tar.gz",
    "platform": null,
    "description": "# StruFi: HTTP Structured Field Values\n\nThis library implements a parser and a serializer for [RFC 9651](https://www.rfc-editor.org/rfc/rfc9651.html) (HTTP Structured Field Values).\n\n\n## Installation\n\nInstall `strufi` by running `pip install git+https://github.com/alma/strufi.git`\n`strufi` package has no dependency.\n\n\n## Usage\n\n### Parser\n\n`strufi` module exposes 3 functions to parse structured field values:\n\n- `load_item` to parse a single item, returning the value with the parameters.\n    ```pycon\n    >>> import strufi\n    >>> strufi.load_item('text/html; charset=utf-8')\n    ('text/html', {'charset': 'utf-8'})\n    ```\n- `load_list` to parse a list of items, returning a list of pairs (value, parameters).\n    ```pycon\n    >>> strufi.load_list('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')\n    [('text/html', {}), ('application/xhtml+xml', {}), ('application/xml', {'q': 0.9}), ('*/*', {'q': 0.8})]\n    ```\n- `load_dict` to parse a map of keys:items, returning values with their parameters.\n    ```pycon\n    >>> strufi.load_dict('u=1, i')\n    {'u': (1, {}), 'i': (True, {})}\n    ```\n\n### Serializer\n\nThe module also exposes functions for the serializing operations, which are the reverse operations of the parsing ones.\n\n- `dump_item` takes a value with parameters and returns the structured field value representation of a single item as a string\n    ```pycon\n    >>> strufi.dump_item(('text/html', {'charset': 'utf-8'}))\n    '\"text/html\";charset=\"utf-8\"'\n    ```\n- `dump_list` takes a list of items and return the structured list representation\n    ```pycon\n    >>> strufi.dump_list([('text/html', {}), ('application/xhtml+xml', {}), ('application/xml', {'q': 0.9}), ('*/*', {'q': 0.8})])\n    '\"text/html\", \"application/xhtml+xml\", \"application/xml\";q=0.9, \"*/*\";q=0.8'\n    ```\n- `dump_dict` takes a dictionnary of key:item and return the structured dict representation\n    ```pycon\n    >>> strufi.dump_dict({'u': (1, {}), 'i': (True, {})})\n    'u=1, i'\n    ```\n\n## Development\n\n### Environment\n\nUse `pip install -e '.[dev]'` to install `strufi` with development dependencies (tests & lint) in your local (virtual) environment.\n\nHere are the tools you can use to reproduce the checks made by the continuous integration workflow:\n\n- `ruff format --diff` to check file format (you can run `ruff format` to apply changes)\n- `ruff check` to check for specific linting rules\n- `mypy .` to check for type annotations consistency\n- `pytest -vv` to run tests suit\n\nAll these commands are also available through a Makefile that also takes care of the virtual environment: `make lint`, `make mypy` and `make tests`.\nYou could also run `make all` or simply `make` to execute the three tasks.\n\n### Contributing\n\nFeel free to [open issues](https://github.com/alma/strufi/issues) to report bugs or ask for features and to open pull-requests to work on existing issues.\n\nThe code of the project is published under [MIT license](https://github.com/alma/strufi/blob/main/LICENSE).\n\n### Packaging\n\nBuild dependencies can be installed with `pip install -e '.[build]'`.\n\nThen the package can be built with `python -m build` (or `make build`) and [uploaded on PyPI](https://pypi.org/project/strufi/) with `twine upload dist/*` (or `make upload` that builds & uploads the package).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Parser for HTTP Structured Field Values",
    "version": "1.0.0",
    "project_urls": {
        "homepage": "https://github.com/alma/strufi"
    },
    "split_keywords": [
        "http",
        " structured field values",
        " rfc 8941",
        " rfc 9651"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "663321768763ab03ee17e6621bea5707345c02c4aaec2b6961e782a5298014f1",
                "md5": "ccde277460372dd7aec47e17ccec05a2",
                "sha256": "372831816d5eab22d5bbe8cb5b13e25f2c5297e712e1d1a959c91a6faaed8cd6"
            },
            "downloads": -1,
            "filename": "strufi-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ccde277460372dd7aec47e17ccec05a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 9262,
            "upload_time": "2025-07-10T14:23:44",
            "upload_time_iso_8601": "2025-07-10T14:23:44.559698Z",
            "url": "https://files.pythonhosted.org/packages/66/33/21768763ab03ee17e6621bea5707345c02c4aaec2b6961e782a5298014f1/strufi-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cfde3d412197e1d33e36f521d0fb0ebdec2b1211606554ed653fc82e1d589b9a",
                "md5": "e91eb003e6dfa73aa50d3bda11f18f3b",
                "sha256": "cf3ef5ca6fc8612573e4d1f6b456471f551ed52bd40e4e653d681001c01559aa"
            },
            "downloads": -1,
            "filename": "strufi-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e91eb003e6dfa73aa50d3bda11f18f3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 15009,
            "upload_time": "2025-07-10T14:23:45",
            "upload_time_iso_8601": "2025-07-10T14:23:45.745892Z",
            "url": "https://files.pythonhosted.org/packages/cf/de/3d412197e1d33e36f521d0fb0ebdec2b1211606554ed653fc82e1d589b9a/strufi-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 14:23:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alma",
    "github_project": "strufi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "strufi"
}
        
Elapsed time: 0.54348s