Skip to main content

Fast quoting and unquoting of urls.

Project description

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.

Project details


Download files

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

Source Distribution

urlquote-2.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

urlquote-2.2.0-py3-none-win_amd64.whl (59.8 kB view details)

Uploaded Python 3Windows x86-64

urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (169.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl (154.1 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file urlquote-2.2.0.tar.gz.

File metadata

  • Download URL: urlquote-2.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for urlquote-2.2.0.tar.gz
Algorithm Hash digest
SHA256 d5cc48768760372b6de936528bd29cbf74544c588358f05848d8d944a9c65af6
MD5 2c9ab1b47fd8cac8567f188ec8230701
BLAKE2b-256 0d7cd3cccf18d31ea4ec59ae97be93d4120c4c1937c44605332a2c653930a5ee

See more details on using hashes here.

File details

Details for the file urlquote-2.2.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: urlquote-2.2.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 59.8 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for urlquote-2.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ecf93fc1636ee5e982b28b029eadf140d98146039f2816f534cc099d2a2b84d8
MD5 d3c2818c314965d5519d8422533fc57a
BLAKE2b-256 9614c1c0bbe4cc5e1160388162bdcf747650d8210d318c870c170ea4d55aa608

See more details on using hashes here.

File details

Details for the file urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for urlquote-2.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d9abc59b3c976f0d681945976f8feaf8672acd8dce978f9bb524d928a99d946
MD5 5766e0dbebec285f1d713b6e2afc077c
BLAKE2b-256 979981733a08d24f2b8a574baa3e88ccc67a247378306cd9fe0d96f5e7f9de3f

See more details on using hashes here.

File details

Details for the file urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for urlquote-2.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 880520e9b3e3edf096a7713d95b9ef196fc5f6a10996c21acd983f0dbd1c3ca6
MD5 f11ba75e75fab551e40cd0544908ba43
BLAKE2b-256 a8c0abf3277e1d0b9a7a242f2a25150f3868b2b64293bb8d6f2ae649c5d49f11

See more details on using hashes here.

Supported by

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