Get metadata of a python package

In this article, we shall see how to find the metadata from a python package installed via pip from the pypi.org. Python has a built-in library called importlib_metadata which can be used to obtain these data.

What metadata can be obtained?

This library has a class called metadata which can be used to get almost any data other than the version number. If you have looked at any of the package details from the pypi.org, you would have seen various details such as author name, repository link, home page and etc.

All these informations can be obtained with this module. Some of the metadata given by this module are

  1. Name
  2. Version
  3. Summary
  4. Home-page
  5. Author
  6. Author-email
  7. Lisence
  8. Documentation
  9. Source
  10. md file data (long description)

How to use this module?

Import the metadata class from the importlib_metadata library. Give the name of the python package as an argument to the metadata class.

from importlib_metadata import metadata
print(metadata('pillow'))

The output of the above code is,

Metadata-Version: 2.1
Name: Pillow
Version: 7.1.2
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: [email protected]
License: HPND
Project-URL: Documentation, https://pillow.readthedocs.io
Project-URL: Source, https://github.com/python-pillow/Pillow
Project-URL: Funding, https://tidelift.com/subscription/pkg/pypi-pillow?utm_source=pypi-pillow&utm_medium=pypi
Keywords: Imaging
Platform: UNKNOWN
Classifier: Development Status :: 6 - Mature
Classifier: License :: OSI Approved :: Historical Permission Notice and Disclaimer (HPND)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Digital Camera
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Screen Capture
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
Classifier: Topic :: Multimedia :: Graphics :: Viewers
Requires-Python: >=3.5

Pillow
======

Python Imaging Library (Fork)
-----------------------------

Pillow is the friendly PIL fork by `Alex Clark and Contributors `_. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. As of 2019, Pillow development is `supported by Tidelift `_.

.. start-badges

.. list-table::
    :stub-columns: 1

    * - docs
      - |docs|
    * - tests
      - |linux| |macos| |windows| |gha_lint| |gha| |gha_windows| |gha_docker| |coverage|
    * - package
      - |zenodo| |tidelift| |version| |downloads|
    * - social
      - |gitter| |twitter|

.. end-badges

More Information
----------------

- `Documentation `_

  - `Installation `_
  - `Handbook `_

- `Contribute `_

  - `Issues `_
  - `Pull requests `_

- `Changelog `_

  - `Pre-fork `_

Report a Vulnerability
----------------------

To report a security vulnerability, please follow the procedure described in the `Tidelift security policy `_.

.. |docs| image:: https://readthedocs.org/projects/pillow/badge/?version=latest
   :target: https://pillow.readthedocs.io/?badge=latest
   :alt: Documentation Status

.. |linux| image:: https://img.shields.io/travis/python-pillow/Pillow/master.svg?label=Linux%20build
   :target: https://travis-ci.org/python-pillow/Pillow
   :alt: Travis CI build status (Linux)

.. |macos| image:: https://img.shields.io/travis/python-pillow/pillow-wheels/master.svg?label=macOS%20build
   :target: https://travis-ci.org/python-pillow/pillow-wheels
   :alt: Travis CI build status (macOS)

.. |windows| image:: https://img.shields.io/appveyor/build/python-pillow/Pillow/master.svg?label=Windows%20build
   :target: https://ci.appveyor.com/project/python-pillow/Pillow
   :alt: AppVeyor CI build status (Windows)

.. |gha_lint| image:: https://github.com/python-pillow/Pillow/workflows/Lint/badge.svg
   :target: https://github.com/python-pillow/Pillow/actions?query=workflow%3ALint
   :alt: GitHub Actions build status (Lint)

.. |gha_docker| image:: https://github.com/python-pillow/Pillow/workflows/Test%20Docker/badge.svg
   :target: https://github.com/python-pillow/Pillow/actions?query=workflow%3A%22Test+Docker%22
   :alt: GitHub Actions build status (Test Docker)

.. |gha| image:: https://github.com/python-pillow/Pillow/workflows/Test/badge.svg
   :target: https://github.com/python-pillow/Pillow/actions?query=workflow%3ATest
   :alt: GitHub Actions build status (Test Linux and macOS)

.. |gha_windows| image:: https://github.com/python-pillow/Pillow/workflows/Test%20Windows/badge.svg
   :target: https://github.com/python-pillow/Pillow/actions?query=workflow%3A%22Test+Windows%22
   :alt: GitHub Actions build status (Test Windows)

.. |coverage| image:: https://codecov.io/gh/python-pillow/Pillow/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/python-pillow/Pillow
   :alt: Code coverage

.. |zenodo| image:: https://zenodo.org/badge/17549/python-pillow/Pillow.svg
   :target: https://zenodo.org/badge/latestdoi/17549/python-pillow/Pillow

.. |tidelift| image:: https://tidelift.com/badges/package/pypi/Pillow?style=flat
   :target: https://tidelift.com/subscription/pkg/pypi-pillow?utm_source=pypi-pillow&utm_medium=badge

.. |version| image:: https://img.shields.io/pypi/v/pillow.svg
   :target: https://pypi.org/project/Pillow/
   :alt: Latest PyPI version

.. |downloads| image:: https://img.shields.io/pypi/dm/pillow.svg
   :target: https://pypi.org/project/Pillow/
   :alt: Number of PyPI downloads

.. |gitter| image:: https://badges.gitter.im/python-pillow/Pillow.svg
   :target: https://gitter.im/python-pillow/Pillow?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
   :alt: Join the chat at https://gitter.im/python-pillow/Pillow

.. |twitter| image:: https://img.shields.io/badge/tweet-on%20Twitter-00aced.svg
   :target: https://twitter.com/PythonPillow
   :alt: Follow on https://twitter.com/PythonPillow




Process finished with exit code 0

Conclusion

Hope this article is helpful. If you have any queries leave them in the comments below.

Happy coding!