acceptlang

A package for parsing Accept-Language tag received from (untrusted) client context.


License
Other
Install
pip install acceptlang==0.0.5

Documentation

Simple package for parsing Accept-Language tag.

This package can be used in the server environment to parse the Accept-Language header.

Test cases and code copied from Django source code enhanced with typing.

Purpose of this code is to be able to use a battle-tested Accept-Language parsing logic in Python code without need to install Django package.

Installation

You can install the package via pip:

pip install acceptlang

Usage

from acceptlang import parse_accept_lang_header

result = parse_accept_lang_header("en-us,en;q=0.5,de;q=0.3")
assert result == (('en-us', 1.0), ('en',0.5), ('de',0.3))

result = parse_accept_lang_header("en-us,*;q=0.5")
assert result == (('en-us', 1.0), ('*',0.5))

Check tests for more examples.

Local development

python3 -m venv venv
. venv/bin/activate
python3 -m pip install -r requirements.dev.txt

Build and publish

python3 -m build --wheel
twine check dist/**
twine upload dist/