Fast url quoting / unquoting for Python
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Fast percent encoding / decoding for python.

This library is not intended to be a replacement for urllib. urllib is part of the Python standard library and should be your go-to choice to quote and unquote URLs. However, should quoting or unquoting of URLs be known to be a performance bottleneck and you are fine with the encoding described below, then by all means have fun using this library.


from urlquote import quote

quoted = quote('/El Niño/')
assert(quoted == '/El%20Ni%C3%B1o/'.encode('utf-8'))


Since this library uses a cffi interface it should work fine with any version of Python. For Linux the wheel has to be build against a version of libc older or equal to the version of libc on the platform the wheel will be used on.


pip install urlquote

quote operates on UTF-8-encoded bytes. If passed a string, it will encode it into UTF-8 first. It will always return UTF-8-encoded bytes. unquote behaves the same way.


All ASCII characters less than 0x20 and greater than 0x7E are encoded. This includes special characters such as line feed, carriage return, NULL, etc. . Aside from these, space, double quote (") , hash (#), inequality qualifiers (<), (>), backtick (`), question mark (?), and curly brackets ({), (}) are also encoded.


This library is a thin wrapper around the Rust crate percent-encoding. It exposes part of its functionality to python via a C interface using milksnake.

To build it you need to install Rust and Cargo. Than you can proceed to build the wheel with:

python build sdist bdist_wheel

To execute the Python tests use:

pip install -e .

There are also some Rust-only unit tests. To execute them change into the rust subdirectory and call.

cargo test

With the nightly toolchain installed you may also call the Rust-only benchmarks using:

cargo +nightly bench


This tool is provided as is under an MIT license without any warranty or SLA. You are free to use it as part for any purpose, but the responsibility for operating it resides with you. We appreciate your feedback though. Contributions on GitHub are welcome.