Skip to content

Instantly share code, notes, and snippets.

@jaraco
Created December 7, 2020 00:28
Show Gist options
  • Save jaraco/fa1bfe2feb7fb229e37b8b8e519c7a17 to your computer and use it in GitHub Desktop.
Save jaraco/fa1bfe2feb7fb229e37b8b8e519c7a17 to your computer and use it in GitHub Desktop.
~ $ python
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> import zipfile
>>> import io
>>> import importlib.metadata
>>> url = 'https://files.pythonhosted.org/packages/2d/c6/59aa4188e7eddb9e89ec67a51598ca6bfc09f1b38c9b45f7ee45af7a4df4/httpx-0.16.1-py3-none-any.whl'
>>> stream = urllib.request.urlopen(url)
>>> buf = io.BytesIO(stream.read())
>>> zf = zipfile.ZipFile(buf)
>>> wheel = zipfile.Path(zf)
>>> md_dir, = (p for p in wheel.iterdir() if p.name.endswith('.dist-info'))
>>> md = importlib.metadata.PathDistribution(md_dir).metadata
>>> list(md)
['Metadata-Version', 'Name', 'Version', 'Summary', 'Home-page', 'Author', 'Author-email', 'License', 'Project-URL', 'Project-URL', 'Platform', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Classifier', 'Requires-Python', 'Description-Content-Type', 'Requires-Dist', 'Requires-Dist', 'Requires-Dist', 'Requires-Dist', 'Provides-Extra', 'Requires-Dist', 'Provides-Extra', 'Requires-Dist']
>>> md.get_all('Provides-Extra')
['brotli', 'http2']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment