Skip to main content

Urlquote

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.

Usage

from urlquote import quote

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

Compatibility

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.

Installation

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.

Encoding

The following encodings are offered. DEFAULT_QUOTING is used in case the quoting parameter is not specified.

Name Additional encoded characters
SIMPLE_QUOTING
DEFAULT_QUOTING space, <,>,`,?,{,}
QUERY_QUOTING space, ",#,<,>
PATH_SEGMENT_QUOTING space, ",#,<,>,`,?,%,/
USERINFO_QUOTING space, ",#,<,>,`,?,{,},/,:,;,=,@,\,[,],^,|
PYTHON_3_7_QUOTING space, ",#,<,>,`,?,{,},$,%,&,\,(,),,,=,;,:,!,@,[,],^,|,+,*
IDEMPOTENT_QUOTING space, ",#,<,>,`,?,{,},$,&,\,(,),,,=,;,:,!,@,[,],^,|,+,*

Non printable and non standard ASCII characters are always quoted. The PYTHON_3_7_QUOTING is going to work the same way in every Python version the name is only refering to the urllib default encoding used in Python 3.7. IDEMPOTENT_QUOTING is the same as PYTHON_3_7_QUOTING but without % to provide idempotency.

Development

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 cffi.

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

python -m pip install build

To setup the development environment run:

python -m pip install -e .[test]

To execute the tests run

pytest

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

cargo test

Links

Support

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.

Release files for urlquote 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for urlquote 2.2.0
File Size Uploaded
urlquote-2.2.0.tar.gz 10.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for urlquote 2.2.0
File Interpreter ABI Platform
urlquote-2.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 393.6 kB

Release files / urlquote-2.2.0.tar.gz

Download URL urlquote-2.2.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d5cc48768760372b6de936528bd29cbf74544c588358f05848d8d944a9c65af6
BLAKE2b-256 checksum
How to use checksums
0d7cd3cccf18d31ea4ec59ae97be93d4120c4c1937c44605332a2c653930a5ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release files / urlquote-2.2.0-py3-none-win_amd64.whl

Download URL urlquote-2.2.0-py3-none-win_amd64.whl
Size 59.8 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ecf93fc1636ee5e982b28b029eadf140d98146039f2816f534cc099d2a2b84d8
BLAKE2b-256 checksum
How to use checksums
9614c1c0bbe4cc5e1160388162bdcf747650d8210d318c870c170ea4d55aa608
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release files / urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 169.0 kB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3d9abc59b3c976f0d681945976f8feaf8672acd8dce978f9bb524d928a99d946
BLAKE2b-256 checksum
How to use checksums
979981733a08d24f2b8a574baa3e88ccc67a247378306cd9fe0d96f5e7f9de3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl

Download URL urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl
Size 154.1 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
880520e9b3e3edf096a7713d95b9ef196fc5f6a10996c21acd983f0dbd1c3ca6
BLAKE2b-256 checksum
How to use checksums
a8c0abf3277e1d0b9a7a242f2a25150f3868b2b64293bb8d6f2ae649c5d49f11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

2.2.0 This release

4 release files

2.1.0

4 release files

2.0.0

4 release files

1.1.4

5 release files

1.1.3

5 release files

1.1.2

4 release files

1.1.1

4 release files

1.1.0

4 release files

1.0.0

4 release files

0.1.8

1 release file

0.1.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page