Skip to main content

A simple url parsing library for python

Project description

P.url is a simple url parsing library for python. Currently, you can modify querystrings for given urls by adding or deleting. Chaining is supported!

Usage

Add/update query

from purl import Purl

url = Purl('https://github.com/search?q=cat')

str(url.add_query('q', 'dog')) # => 'https://github.com/search?q=dog'
url = Purl('https://github.com/search')

str(url.add_query({
  'q': 'cat',
  'l': 'JavaScript',
  'type': 'Issues'
}))

# or

url = Purl('https://github.com/search')

str(url.add_query('q', 'cat')
  .add_query('l', 'JavaScript')
  .add_query('type', 'Issues')) # => 'https://github.com/search?l=JavaScript&q=cat&type=Issues'

Delete query

from purl import Purl

url = Purl('https://github.com/search?q=cat')

str(url.delete_query('q')) # => 'https://github.com/search'
url = Purl('https://github.com/search?l=JavaScript&q=cat&type=Issues')

str(url.delete_query(['q', 'type'])) # => https://github.com/search?l=JavaScript

# or

url = Purl('https://github.com/search?l=JavaScript&q=cat&type=Issues')
str(url.delete_query('q')
  .delete_query('type')) # => 'https://github.com/search?l=JavaScript'

Params

url = ( Purl('https://some.public.api.com')
  .path('/:resource/:id/:action')
  .param('resource', 'user').param('id', 12).param('action', 'favorites')
)
str(url)

# or

url = ( Purl('https://some.public.api.com')
  .path('/:resource/:id/:action')
  .param({
    'resource': 'user',
    'id': 12,
    'action': 'favorites'
  })
)
str(url) # => 'https://some.public.api.com/user/12/favorites'

Running the tests

make sure you have py test installed

pip install pytest

Then run:

py.test

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

p.url-0.1.0a4.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file p.url-0.1.0a4.tar.gz.

File metadata

  • Download URL: p.url-0.1.0a4.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for p.url-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 1f5fc1cad269108d96089a2a9244ece90fc7c962800bd0a528936b394e639abc
MD5 c1df900bf5093abab4514c4f9afa250f
BLAKE2b-256 cf56e36096056649758114fec535a4b1be7259c2ba556931b3ed9dcc712e33a7

See more details on using hashes here.

Supported by

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