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

Uploaded Source

Built Distributions

urlquote-2.0.0-py3-none-win_amd64.whl (64.6 kB view details)

Uploaded Python 3 Windows x86-64

urlquote-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (464.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

urlquote-2.0.0-py3-none-macosx_10_7_x86_64.whl (142.1 kB view details)

Uploaded Python 3 macOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: urlquote-2.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for urlquote-2.0.0.tar.gz
Algorithm Hash digest
SHA256 03479d99bd2e3ebc7763770cde1276f05f8687c8b8356c83d4095def58754b1d
MD5 6b3e211b9eb81c23863d2266bb1456e0
BLAKE2b-256 f3accf26e36351fb949cade5d6dd5bc2bfcd0eb6785d692a1fa45d3c1531da1b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for urlquote-2.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8fe47d91831b3a2438cee2005790672d44e8f77082e86d341a9eabaceb85eb0d
MD5 0c838e21eb48d1ce917ec7b862beecd0
BLAKE2b-256 23910863f1e841e8abbd27d0436e2cbded066129f69594404706a411ca329517

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for urlquote-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 196d6275829d4c3df02f6732f6b5ffe4b00ea74def2a66eb9139f01eaff2d0fc
MD5 e9df8f922099edae7bc1c673498f9932
BLAKE2b-256 9c033ccc0bb7f8d8f3f06c8d9bd6d08f5b02c78c0d6acbf0d3c806b1fbf63b43

See more details on using hashes here.

File details

Details for the file urlquote-2.0.0-py3-none-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for urlquote-2.0.0-py3-none-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 cbae0c05796a39764d06315ff4c548c918b7feb435a4cd6cd6a7dfb33fd9eb8a
MD5 5a4611d5f6da3d8385b68d1763ceee04
BLAKE2b-256 9f25b708cf2a178c37f988323ce2e95232867280afd9686e5c3c04d5f8a0416e

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