Using External Libraries — typing documentation
Navigation index next | previous | Python » typing documentation » Using External Libraries | Theme | Using External Libraries ¶ See also If you are looking for information on how to write type hints for external libraries, see the Writing and Maintaining Stub Files guide. Many external libraries – whether installed from the Python Package Index (PyPI) or from other sources – provide their own type hints. This is indicated by the presence of a py.typed file in the library’s root directory.
If you install such a library, you can use it with any type checker without any additional configuration. Type hints can either be included in the library’s source code the same way as in your own code, or they can be provided in separate so-called stub files . Stub files are named <module>.pyi and contain only type hints, without any implementation. For libraries that don’t include their own type hints, a separate stub package may provide them.
These stub packages are often written by the library authors themselves, by the contributors to the typeshed project, or by third-party contributors. These packages are usually named types-<library> or <library>-stubs . These packages can be installed from PyPI as usual, and they will be automatically discovered by type checkers: pip install requests types - requests Warning The usual security considerations apply when installing third-party packages.
Only install packages from sources you trust. Stub packages have the same security implications as any other package. Previous topic Static Typing with Python Next topic Typing Python Libraries This Page Show Source Quick search Navigation index next | previous | Python » typing documentation » Using External Libraries | Theme | © Copyright 2021, The Python Typing Team. This page is licensed under the Python Software Foundation License Version 2.
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License. The Python Software Foundation is a non-profit corporation. Please donate. Created using Sphinx 9.1.0.