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, ",#,<,>,`,?,{,},$,%,&,\,(,),,,=,;,:,!,\,@,[,],^,`

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.

Development

a 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 setup.py build sdist bdist_wheel

To execute the Python tests use:

pip install -e .
pytest test.py

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

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-1.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distributions

urlquote-1.1.0-py2.py3-none-win_amd64.whl (111.4 kB view details)

Uploaded Python 2 Python 3 Windows x86-64

urlquote-1.1.0-py2.py3-none-manylinux2010_x86_64.whl (620.3 kB view details)

Uploaded Python 2 Python 3 manylinux: glibc 2.12+ x86-64

urlquote-1.1.0-py2.py3-none-macosx_10_6_intel.whl (90.3 kB view details)

Uploaded Python 2 Python 3 macOS 10.6+ intel

File details

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

File metadata

  • Download URL: urlquote-1.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.1

File hashes

Hashes for urlquote-1.1.0.tar.gz
Algorithm Hash digest
SHA256 bb3022bcd985d0854cddcee963c5f7e415b876c2a905cebf4a15b8ffb6df723a
MD5 f9c88213139cec930c267f6b5a49aac2
BLAKE2b-256 b4ff3e4e8087a950e5f1989e61019b2988c11b5502982eb01c81330f0127cb90

See more details on using hashes here.

File details

Details for the file urlquote-1.1.0-py2.py3-none-win_amd64.whl.

File metadata

  • Download URL: urlquote-1.1.0-py2.py3-none-win_amd64.whl
  • Upload date:
  • Size: 111.4 kB
  • Tags: Python 2, Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3

File hashes

Hashes for urlquote-1.1.0-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 23d840df2458b9a6fdd58a81b5344017bc0da552806062872755d89a82fbb7ac
MD5 02ef2b15b317c260f446d99c426ab581
BLAKE2b-256 079e15aeeb52bfbda04108e85360027fa6838d6a247bda62f7a1bc8a2b3037fa

See more details on using hashes here.

File details

Details for the file urlquote-1.1.0-py2.py3-none-manylinux2010_x86_64.whl.

File metadata

  • Download URL: urlquote-1.1.0-py2.py3-none-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 620.3 kB
  • Tags: Python 2, Python 3, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.1

File hashes

Hashes for urlquote-1.1.0-py2.py3-none-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 133b1a583961bab2b38630dc2ca15813d0ac57246d61e4545e80065a9ab903b9
MD5 105d7922b1a3d73d67596641215247da
BLAKE2b-256 cfcf02a7cbde8a463a279ad790104b41edb16fda98496518001c62b47cc32dd4

See more details on using hashes here.

File details

Details for the file urlquote-1.1.0-py2.py3-none-macosx_10_6_intel.whl.

File metadata

  • Download URL: urlquote-1.1.0-py2.py3-none-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.3 kB
  • Tags: Python 2, Python 3, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.1

File hashes

Hashes for urlquote-1.1.0-py2.py3-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 43104af969ad05b7e6e68a4a8e36642e136f9ecb895af937e991c68704d406d7
MD5 26caf4b5f1e3a3a8ce6ebd9365427ff7
BLAKE2b-256 2a7fcab7ce6744b175ed37f654521ae6100915e0dd77090c3368c014d6cfd33f

See more details on using hashes here.

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