Skip to main content

urllib.request handler for scheme ppr: Python Package Resource files.

Project description

PprHandler

urllib.request.BaseHandler for URLs with scheme ppr, pointing to Python Package Resource files.

Using URL terminology, the URL consists of

  • a scheme: ppr
  • an authority: module name
  • a path: package resource file path

for example ppr://ppr_handler/py.typed.

It also registers ppr with urllib.parse as a scheme that uses netloc and relative URLs.

Installation

pip install ppr-handler

Usage

import ppr_handler
from urllib.request import build_opener

opener = build_opener(ppr_handler.PprHandler())
# or: opener = ppr_handler.build_opener()

with opener.open("ppr://ppr_handler/py.typed") as file:
    print(file.read())
    # b'# Marker file for PEP 561.\n'

or, for global use with urllib.request,

import ppr_handler
from urllib.request import build_opener, install_opener, urlopen

install_opener(build_opener(ppr_handler.PprHandler()))

with urlopen("ppr://ppr_handler/py.typed") as file:
    print(file.read())
    # b'# Marker file for PEP 561.\n' 

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

ppr-handler-0.0.2.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

ppr_handler-0.0.2-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

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