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

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

Uploaded Source

Built Distributions

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

Uploaded Python 2 Python 3 Windows x86-64

urlquote-1.1.1-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.1-py2.py3-none-macosx_10_6_intel.whl (90.2 kB view details)

Uploaded Python 2 Python 3 macOS 10.6+ intel

File details

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

File metadata

  • Download URL: urlquote-1.1.1.tar.gz
  • Upload date:
  • Size: 12.3 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.1.tar.gz
Algorithm Hash digest
SHA256 4b3920f7e2653e05c92f3b1b11e8fe992e767884556d095ee82ee1a4c8213a46
MD5 0de1465bcdfe52ab779a25b6857026d3
BLAKE2b-256 e9d4768ccaed6fbfb5c4e918a1136df8af1750961f05bc9fcd72a4dc2d1edb12

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urlquote-1.1.1-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.1-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4493754aff0ce8602eba13ba6e7e88a0c2fe131ec5d3159ff11900243acf9a0c
MD5 749f98d9ed72c5510ca5e797857062ce
BLAKE2b-256 f4da82cf5a3cb1be70d274bebc5b7bd89e055ae90a26f5aab23b93bcdf312db1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urlquote-1.1.1-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.1-py2.py3-none-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 36dfbe90e3a1a942a5a9b197802e9dd172ddc8f89016451ebabb6962a77b3f40
MD5 8d8be884001e197204fa42d5c0f5901d
BLAKE2b-256 9e6ab6d70477fe7274f5b3c0aa014e7dc224cc3f739be54f0d20f9f0d39e824f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urlquote-1.1.1-py2.py3-none-macosx_10_6_intel.whl
  • Upload date:
  • Size: 90.2 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.1-py2.py3-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 15cb66911b90d1c9cb389d6a5c2d3fcab9f0ec8d0dfe8e5776e8ab948013a99b
MD5 28e40e83393e90a4f0a18148d4e2ee60
BLAKE2b-256 34b8856853c0622e26d5af39b335fa0de0d3a82e0be00ff29889825f1729052c

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