Blender-stubs is now available on PyPI, providing type hinting for popular IDEs

Hi, I’ve been working on a new FOSS project called bpystubgen for a while.

As the name suggests, it is an API stub generator for UPBGE and Blender, which produces a Python module you can install to make your IDE provide auto-completion and documentation support for relevant APIs:


(Auto-completion at work in PyCharm)


(Pop-up documentation shown in VSCode)

For Blender, you can install blender-stubs with a package manager like pipenv or pip as explained on the homepage.

Currently, a daily snapshot of the module is available for the upcoming Blender 3.0 release, as well as versions for Blender from 2.80 to 2.93 (see the instruction for how to specify an appropriate version).

I’d appreciate it if you could try it and let me know how it works. In case you have suggestions or encountered a problem, please give me feedback using the project’s issue tracker.

Thanks!

7 Likes

Does this work with the Text Editor too?

Could it work with something like this? https://github.com/tin2tin/Intellisense_for_Blender_Text_Editor/blob/Ctrl%26Space/intellisense_addon.py

I had issues with completion when using bpy.data with fake-bpy-module Does Blender-stubs do a better job overall with all bpy functions and data models? I guess I am wondering if it has betrer code completion coverage compared to the other solutions.

My module may have its own problems as it’s in an early stage of development. But I believe it can handle bpy.data as expected, as you can see below:

image

There might be certain areas where fake-bpy-module does a better job. But at least I designed my project in a way that it’s easily extended and tested, so that such limitations could be quickly addressed in future.

1 Like

I’m afraid not, unfortunately. My module should be recognised by any IDE that supports the PEP-561 standard. But it doesn’t help when the editor relies on simple keywords matching to implement autocompletion.

Personally, I think it’d be better to use a proper IDE for any serious development. But if one would attempt to add such a feature to Blender’s builtin editor, I suppose using an open source IDE as a backend might be an option. I heard that VSCode supports being used as a library, and Eclim uses Eclipse behind the scene to add IDE features to Vim as well.

2 Likes

Thanks for looking into it. Nevertheless, it seems to be a good project.

I use VsCode atm, and it is generally fine for add-on development. I used to just compile Blender as a Python module and install into the Python folder for completion. That gave me the best completion integration (only when using VsCode with Jedi though), but it can get a bit tedious with recompiling it with the newer Blender versions and doing a clean installation of Python to make sure there are no stale libs around.

Ah, sorry. My last reply was meant for tin2tin’s post :sweat_smile:

This looks like a great project! But I’m not entirely sure how to use it with and IDE (specifically Vscode). Is it enought to just install it from PyPi using pip install blender-stubs==2.93.*?
Because nothing happens in my editor when I do so, and I don’t really know enough about how these things work to know if there’s something else I need to do.
Thanks!

Yes, normally just installing it via pip should be enough, although using some sort of a virtual environment like pipenv would be preferrable for different reasons.

If it doesn’t work on your end, there are a few things I can think of that you may want to check. First off, see if the extension you use for editing Python supports the standard. In my case, it’s just called “Python” (ms-python.python) and it seems to work ok in that regard.

Secondly, find out which Python installation you installed blender-stubs on and make sure that it is chosen as the active interpreter in VSCode which you can choose in the bottom left corner of the IDE.

Other than that, it’s difficult to guess since I mostly use PyCharm for anything related Python and don’t have much experience with VSCode yet. Hopefully, others who are more familiar with the IDE could provide some help, if the above mentioned methods don’t resolve the issue.

2 Likes

Ok, great, thanks for the help!

I’ve made two more releases since I created this thread a couple of days ago.

Normally, I wouldn’t announce every minor release in this forum. But I found that the previous version contained a few non-trivial issues, including the top level leaf modules like bgl or aud not getting generated properly.

The new release also contains several other useful improvements, like better handling of “*args/**kwargs”, or additional “dunder” methods to allow type hinting for vector/euler/matrix operations.

I don’t know how many people other than myself are using my stubs. But if you have already installed the module, you may want to update to the latest version to get the bug fixes and improvements mentioned above.

Thanks!

2 Likes