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

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

Uploaded Source

Built Distributions

urlquote-1.1.2-py2.py3-none-manylinux2010_x86_64.whl (603.1 kB view details)

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

urlquote-1.1.2-py2.py3-none-manylinux1_x86_64.whl (603.1 kB view details)

Uploaded Python 2 Python 3

urlquote-1.1.2-py2.py3-none-macosx_10_6_intel.whl (95.8 kB view details)

Uploaded Python 2 Python 3 macOS 10.6+ Intel (x86-64, i386)

File details

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

File metadata

  • Download URL: urlquote-1.1.2.tar.gz
  • Upload date:
  • Size: 22.7 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.2.tar.gz
Algorithm Hash digest
SHA256 809d356ea660afe5ca57f33ebe659945dafeaa63f7bba25395b8f0663f5704a9
MD5 631d86be4bf3ebb25fe5e600e3a96961
BLAKE2b-256 ea5938dd293014136432a1d5c4821c9ebb96a0c81a9a5435042c6c2508b25e8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urlquote-1.1.2-py2.py3-none-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 603.1 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.2-py2.py3-none-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 075446d82e1391ca7f932523197ebd6e01d02cb84099d05b68ae068eecfd8fd7
MD5 080133ccc02ba824002569fb2faf4a35
BLAKE2b-256 bff251c707d6d64cedb36b680c32e9124ee38e07513c2cbea8481fcdcedcd571

See more details on using hashes here.

File details

Details for the file urlquote-1.1.2-py2.py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: urlquote-1.1.2-py2.py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 603.1 kB
  • Tags: Python 2, Python 3
  • 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.2-py2.py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f7ec605ceee3aba0ceaa7a1db4f3cc12eb050cef2de06396da732ed37de384d7
MD5 5abc4fd38d9715be88defd3c393c3450
BLAKE2b-256 4dcd267338dc175717b57089d5581353e27bd8796ce6e0424d599b79a3801b70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urlquote-1.1.2-py2.py3-none-macosx_10_6_intel.whl
  • Upload date:
  • Size: 95.8 kB
  • Tags: Python 2, Python 3, macOS 10.6+ Intel (x86-64, i386)
  • 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.2-py2.py3-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 6ccaf9347b285d802309de04580550bc0bde4fb6c5e67f23577370585be8d233
MD5 a97b48995ca87f895a9582606d283267
BLAKE2b-256 e0d097f587b3658dcab8b971b3108ed587b251f22ff8b7019372f0c2a2726345

See more details on using hashes here.

Supported by

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