A type to represent, query, and manipulate a Uniform Resource Identifier.
© 2017 Alice Bevan-McGregor and contributors.
Installing uri is easy, just execute the following in a terminal:
pip install uri
Note: We strongly recommend always using a container, virtualization, or sandboxing environment of some kind when developing using Python; installing things system-wide is yucky (for a variety of reasons) nine times out of ten. We prefer light-weight virtualenv, others prefer solutions as robust as Vagrant.
If you add uri to the install_requires argument of the call to setup() in your application’s setup.py file, uri will be automatically installed and made available when your own application or library is installed. We recommend using “less than” version numbers to ensure there are no unintentional side-effects when updating. Use uri<2.1 to get all bugfixes for the current release, and uri<3.0 to get bugfixes and feature updates while ensuring that large breaking changes are not installed.
While uri does not have any hard dependencies on any other package, it is strongly recommended that applications using uri in web-based applications also install the markupsafe package to provide more efficient string escaping and some additional functionality.
Installing the current development version requires Git, a distributed source code management system. If you have Git you can run the following to download and link the development version into your Python runtime:
git clone https://github.com/marrow/uri.git (cd uri; python setup.py develop)
You can then upgrade to the latest version at any time:
(cd uri; git pull; python setup.py develop)
If you would like to make changes and contribute them back to the project, fork the GitHub project, make your changes, and submit a pull request. This process is beyond the scope of this documentation; for more information see GitHub’s documentation.
An abstract string-like (and mapping-like, and iterator-like…) identifier for a resource with the regular form defined by RFC 3986:
For details on these components, please refer to Wikipedia. Each of these components is represented by an appropraite rich datatype:
- The scheme of a URI represents an extensible API of string-like plugins.
- Any IPv6 host is automatically wrapped and unwrapped in square braces.
- The path is represented by a PurePosixPath.
- The query is a rich ordered multi-value bucketed mutable mapping called QSO. (Ouch, but that’s what it is!)
Instantiate a new URI by passing in a string or string-castable object, pathlib.Path compatible object, or object exposing a __link__ method or attribute:
home = URI("https://github.com/marrow/")
The scalar attributes are combined into several compound groups for convienence:
- The credentials are a colon (:) separated combination of: user + password — also accessible via the shorter auth or the longer authentication attributes.
- The authority part is the combination of: credentials + host + port
- The heirarchical part is the combination of: authority part + path
Other aliases are provided for the scalar components, typically for compliance with external APIs, such as interoperability with pathlib.Path or urlsplit objects:
- username is the long form of user.
- hostname is the long form of host.
- authentication is the long form of auth.
In addition, several string views are provided for convienence, but ultimately all just call str() against the instance or one of the compound groups described above:
- uri represents the entire URI as a string.
- safe_uri represents the enture URI, sans any password that may be present.
- base is the combination of scheme and the heirarchical part.
- summary is a useful shortcut for web presentation containing only the host and port of the URI.
- qs is just the query string, as a plain string instead of QSO instance.
URI values may be absolute identifiers or relative references. Absolute URIs are what most people see every day:
Indirect references require the context of an absolute identifier in order to resolve them. Examples include:
- //example.com/protocol/relative — protocol implied from context, frequently used in HTML when referencing resources hosted on content delivery networks.
- /host/relative — all elements up to the path are preserved from context, also frequently used in HTML when referencing resources on the same server. This is not equivalent to file:///host/relative, as the protocol is unknown.
- relative/path — the resulting path is relative to the “current working directory” of the context.
- ../parent/relative/path — references may ascend into parents of the context.
- resource#fragment — referencing a specific fragment of a sibling resource.
- #fragment — a same-document reference to a specific fragment of the context.
Two primary methods are provided to combine a base URI with another URI, absolute or relative. The first, utilizing the uri.resolve(uri, **parts) method, allows you to both resolve a target URL as well as provide explicit overrides for any of the above scalar attributes, such as query string. The second, which is recommended for general use, is to use the division and floor division operators:
base = URI("https://example.com/about/us") cdn = base // "cdn.example.com" js = cdn / "script.js" css = cdn / "script.css"
Each URI has a scheme which should be registered with the Internet Assigned Numbers Authority (IANA) which specifies the mechanics of the URI fields. Examples include: http, https, ftp, mailto, file, data, etc.
- Extraction of the URIString object from Marrow Mongo.
- Original package by Jacob Kaplan-Moss. Copyright 2008 and released under the BSD License.
The URI package has been released under the MIT Open Source license.
The MIT License
Copyright © 2017 Alice Bevan-McGregor and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|uri-2.0.0-py2.py3-none-any.whl (47.8 kB) Copy SHA256 hash SHA256||Wheel||3.6||Jun 12, 2017|
|uri-2.0.0.tar.gz (25.1 kB) Copy SHA256 hash SHA256||Source||None||Jun 12, 2017|