Create a stub file for your own implementation
Navigate to the directory where the target implementation resides. Select Python File (alternatively, use the Alt+Insert shortcut).from the main menu, then select
In the New Python file dialog, select Python stub and specify the filename. The filename should be the same as the name of the implementation file.
Press Enter to complete the action.
For your convenience, you can create a separate directory to keep your stub and its implementation. This will help you reuse the stub for your other projects.
Create a stub file for the external implementation
You can create a stub file for some implementations that reside in the packages installed in your environments.
Create a directory for your stub. Right-click the directory and from the context menu select .
In the directory, recreate the hierarchy corresponding to the implementation package.
Within the created structure, navigate to the target directory and select Python File (alternatively, use the Alt+Insert shortcut). In the New Python file dialog, select Python stub and specify the filename. Press Enter and the file will be created. You can put any other required files to the stub directory.from the main menu, then select
Navigate between a stub and its implementation
PyCharm shows an asterisk in the left gutter for those code elements that have stubs. Click the asterisk to jump between a stub and its implementation:
You can make your stubs accessible for your other PyCharm projects.
Click the Project Interpreter selector in the Status Bar and select .
In the Project Interpreter dialog, click and select , then in the opened Project Interpreters dialog, click .
In the Interpreter paths dialog, click to add the new path record:
Inspect your project: the directory with the stub files is now marked as a library root.
Any time you will use this project interpreter to work with other projects, this stub library will be accessible through the path you have just added.
Install a stub package
For the more widely use, you can create a stub package and upload to the pypi repository. See more information in the Packaging Python Projects guide. With the PEP-561 support, you can install stubs packages for your project interpreter.
Install the package. If needed, click Manage repositories to add a repository where your stub packages reside.
Stub packages have a predefined name format, so type "-stubs" in the search field to discover them.
Click Install Package to complete installation.