qs-codec

qs-codec

A query string encoding and decoding library for Python.

Ported from qs for JavaScript.

PyPI - Version PyPI - Downloads PyPI - Status PyPI - Python Version PyPI - Format Black Test CodeQL Publish Docs codecov Codacy flake8 mypy pylint isort Security Status License Contributor Covenant GitHub Sponsors GitHub Repo stars

Highlights

  • Nested dictionaries & lists: foo[bar][baz]=qux{'foo': {'bar': {'baz': 'qux'}}}.

  • Multiple list formats: INDICES (a[0]=x), BRACKETS (a[]=x), REPEAT (a=x&a=y), COMMA (a=x,y) with optional comma round-trip.

  • Dot-notation: parse/encode keys like a.b=c as nested; option to encode dots in keys when using dot notation.

  • Charset handling: UTF-8 (default) and Latin-1; optional charset sentinel (utf8=✓) to auto-detect encoding.

  • Pluggable hooks: custom encoder/decoder callables; options to sort keys, filter output, and control percent-encoding (keys-only, values-only).

  • Nulls & empties: strict_null_handling and skip_nulls; support for empty lists/arrays when desired.

  • Dates: serialize_date for ISO 8601 or custom (e.g., UNIX timestamp).

  • Safety limits: configurable nesting depth, parameter limit, and list index limit; optional strict-depth errors; duplicate-key strategies (combine/first/last).

  • Extras: numeric entity decoding (e.g. ☺ → ☺), alternate delimiters/regex, and query-prefix helpers.

Usage

A simple usage example:

import qs_codec as qs

# Encoding
assert qs.encode({'a': 'b'}) == 'a=b'

# Decoding
assert qs.decode('a=b') == {'a': 'b'}

Indices and tables


Other ports

Port

Repository

Package

Dart

techouse/qs

pub.dev version

Kotlin / JVM + Android AAR

techouse/qs-kotlin

Maven Central version

Swift / Objective-C

techouse/qs-swift

Swift Package Manager version

.NET / C#

techouse/qs-net

NuGet version

Node.js (original)

ljharb/qs

npm version


Special thanks to the authors of qs for JavaScript: - Jordan Harband - TJ Holowaychuk