Generate Python stub files (PYI) from docstrings
Project description
docstub
[!NOTE] In early development!
A command line tool to generate Python stub files (PYI) from type descriptions in NumPyDoc style docstrings.
Installation
pip install docstub[optional]
Usage & configuration
docstub example/example_pkg/
will create stub files for example_pkg/
in example/example_pkg-stubs/
.
For now, refer to docstub --help
for more.
Declare imports and synonyms
Types in docstrings can and are used without having to import them. However, when docstub creates stub files from these docstrings it actually needs to know how to import those unknown types.
[!TIP] docstub already knows about types in Python's
typing
orcollections.abc
modules. That means you can just use types likeLiteral
orSequence
.
For now docstub's relies on users to declare unknown types[^static-analysis]
in a docstub.toml
or pyproject.toml
like this:
[tool.docstub.docnames]
np = { import = "numpy", as = "np" }
With this declaration, you can safely use things that are available in the
numpy
namespace. E.g. docstub will recognize that np.uint8
requires
import numpy as np
and will include it in stub files if necessary.
docstub uses the keys of the docnames
map to match unknown names used in
docstrings. So
[tool.docstub.docnames]
func = { use = "Callable", from = "typing" }
will allow using func
as a synonym for Callable
.
[^static-analysis]: Static and possibly runtime analysis to automatically find unknown types is on the roadmap.
Contributing
TBD
Acknowledgements
Thanks to docs2stubs by which this project was heavily inspired and influenced.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docstub-0.2.1.tar.gz
.
File metadata
- Download URL: docstub-0.2.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38dfaad41a86aaec1b2e40649a8e937f99acd5fc9e4b5c4e2bc8c514d82c19b0 |
|
MD5 | 148c90ec4b41d67e08ca4a0fe66238c5 |
|
BLAKE2b-256 | 47739a6b825924f92f5f67ec481bd120cdd38d36b2dfde44ed457fa2500ff7d1 |
File details
Details for the file docstub-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: docstub-0.2.1-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a771f5753742f3be6fa58433cd6190e59e4b5241534e21edf290652328f39c82 |
|
MD5 | 6f65de7098aaf58eeeb98fd01214fd43 |
|
BLAKE2b-256 | bc38a66fc9b37b703af6cfaecdc32c42daad148ad4f78be0041021657a069ed3 |