purl.URL is a simple, immutable URL class that can make your life easier.
There’s only one class to be aware of.
The constructor can be used in two ways:
Pass a URL string:
>>> URL('http://www.google.com/search?q=testing')
u'http://google.com/search?q=testing'
Pass keyword arguments:
>>> URL(host='www.google.com', path='/search', query='q=testing')
u'http://google.com/search?q=testing'
If you pass both a URL string and keyword args, then the values of keyword args take precedence.
Add a new path segment to the end of the current string
| Parameters: | value (string) – the new path segment to use |
|---|
Example:
>>> u = URL('http://example.com/foo/')
>>> u.add_path_segment('bar')
u'http://example.com/foo/bar'
Return the host
| Parameters: | value (string) – new host string |
|---|
Return or set the fragment (hash)
| Parameters: | value (string) – the new fragment to use |
|---|---|
| Returns: | string or new URL instance |
Factory method to create a new instance based on a passed string
This method is deprecated now
Test if a given query parameter is present
| Parameters: | key (string) – key to test for |
|---|
Test if a given set of query parameters are present
| Parameters: | keys (list) – keys to test for |
|---|
Return the host
| Parameters: | value (string) – new host string |
|---|
Return the netloc
Return the password
Return or set the path
| Parameters: | value (string) – the new path to use |
|---|---|
| Returns: | string or new URL instance |
Return the path segment at the given index
| Parameters: |
|
|---|
Return the path segments
| Parameters: | value (list) – the new path segments to use |
|---|
Return or set the port
| Parameters: | value (string) – the new port to use |
|---|---|
| Returns: | string or new URL instance |
Return or set the query string
| Parameters: | value (string) – the new query string to use |
|---|---|
| Returns: | string or new URL instance |
Return a query parameter for the given key
| Parameters: |
|
|---|
Return a dictionary of query params
| Parameters: | value (dict) – new dictionary of values |
|---|
Return or set the scheme.
| Parameters: | value (string) – the new scheme to use |
|---|---|
| Returns: | string or new URL instance |
Return a subdomain or set a new value and return a new URL instance.
| Parameters: |
|
|---|
Returns a list of subdomains or set the subdomains and returns a new URL instance.
| Parameters: | value (list) – a list of subdomains |
|---|
Return the username