Skip to main content

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

Project description

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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

acceptlang-0.0.5-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page