Better URI Handling
Project description
# PyURI
[![Build Status](https://travis-ci.org/nick-allen/pyuri.svg?branch=master)](https://travis-ci.org/nick-allen/pyuri)
[![Coverage Status](https://coveralls.io/repos/github/nick-allen/pyuri/badge.svg?branch=master)](https://coveralls.io/github/nick-allen/pyuri?branch=master)
[![PyPI version](https://badge.fury.io/py/pyuri.svg)](https://badge.fury.io/py/pyuri)
Better URI handling
Tested with Python 2.7 and 3.6
---
## Install
`pip install pyuri`
## Usage
Raw URI string parsing:
```python
from pyuri import URI
uri = URI('http://localhost:80/path/to/file?query=value#/fragment/path')
assert uri.scheme == 'http'
assert uri.host == 'localhost'
assert uri.port == 80
assert uri.path == '/path/to/file'
assert uri.query == 'query=value'
assert uri.fragment == '/fragment/path'
```
Composition by parts
```python
from pyuri import URI
uri = URI(scheme='ftp', host='localhost', port=8000, query='key=value')
assert str(uri) == 'ftp://localhost:8000?key=value'
```
Modification and comparison
```python
from pyuri import URI
uri1 = URI('https://example.com:80')
uri2 = URI('https://example.com:443/new/path')
assert uri1 != uri2
uri1.port = 443
uri1.path = '/new/path'
assert str(uri1) == 'https://example.com:443/new/path'
assert uri1 == uri2
```
Additional helpers
```python
from pyuri import URI
uri = URI('http://localhost:80/path/to/file?repeat=value1&repeat=value2&escape=escaped%20value#/fragment/path')
# Access query parameters as dictionary
assert uri.query_dict() == {
'repeat': ['value1', 'value2'],
'escape': ['escaped value']
}
```
[![Build Status](https://travis-ci.org/nick-allen/pyuri.svg?branch=master)](https://travis-ci.org/nick-allen/pyuri)
[![Coverage Status](https://coveralls.io/repos/github/nick-allen/pyuri/badge.svg?branch=master)](https://coveralls.io/github/nick-allen/pyuri?branch=master)
[![PyPI version](https://badge.fury.io/py/pyuri.svg)](https://badge.fury.io/py/pyuri)
Better URI handling
Tested with Python 2.7 and 3.6
---
## Install
`pip install pyuri`
## Usage
Raw URI string parsing:
```python
from pyuri import URI
uri = URI('http://localhost:80/path/to/file?query=value#/fragment/path')
assert uri.scheme == 'http'
assert uri.host == 'localhost'
assert uri.port == 80
assert uri.path == '/path/to/file'
assert uri.query == 'query=value'
assert uri.fragment == '/fragment/path'
```
Composition by parts
```python
from pyuri import URI
uri = URI(scheme='ftp', host='localhost', port=8000, query='key=value')
assert str(uri) == 'ftp://localhost:8000?key=value'
```
Modification and comparison
```python
from pyuri import URI
uri1 = URI('https://example.com:80')
uri2 = URI('https://example.com:443/new/path')
assert uri1 != uri2
uri1.port = 443
uri1.path = '/new/path'
assert str(uri1) == 'https://example.com:443/new/path'
assert uri1 == uri2
```
Additional helpers
```python
from pyuri import URI
uri = URI('http://localhost:80/path/to/file?repeat=value1&repeat=value2&escape=escaped%20value#/fragment/path')
# Access query parameters as dictionary
assert uri.query_dict() == {
'repeat': ['value1', 'value2'],
'escape': ['escaped value']
}
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyuri-0.3.1.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for pyuri-0.3.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db8582a7580fa675108dd48f16af0988ee2598a18e80df803ce06909bd842c6 |
|
MD5 | dc9ad4b73c5637b9f762c3f94f73fcdc |
|
BLAKE2b-256 | d796633b4e8e8cf5367eb702c3b07c8c6d352e7697f99a73e6aa00c85fb0e51e |