Logic 2 python api stubs

Would you consider publishing python api stubs for the full saleae HLA interface?

When developing python HLA extensions, it is useful to have intellisense / autocomplete.
Python supports stub files, that can be used for this.

Attached is an initial setup for this, which is manually extracted from API Documentation

Drop the attached files in a folder ‘saleae’ and autocomplete / type hints should mostly be working.
Example of it in action:

saleae.zip (1.5 KB)

1 Like

@Mark Thanks for the suggestion! This sounds like a great idea. I’ll bring this up with our software / product teams during our next meet up.

2 Likes

You know I did get typing working in vscode before but I don’t recall how - I need to look into that.

The python sources for the saleae analyzers module can be found here: "C:\Program Files\Logic\resources\windows\pythonlibs\lib\site-packages\saleae\analyzers"

If I have time I’ll see if I can get something working again in vscode to get intelliSense working.

Those are incomplete, that was my first attempt.
It seems to be missing quite some classes, that are probably written in c or embedded in something.

Extracting the attached zip file works for the most part, but not all my definitions (based on the api docs) are fully complete.

Hey @timreyes, are you aware if there’s update on providing stubs? I am currently developing my HLA using the Python files from the installation directory, but it’s far from perfect. No need for a library, just stubs would be nice for proper code editor support.

Thanks for the follow up! I just took a crack at this with claude code, and it seems to work very well. Eventually I want to get the creation of this more formalized, and integrated into the application, templates, and documentation, but in the short term, anyone can use these typings to improve their experience authoring Saleae HLAs.

This just supports HLAs for the moment, but please let me know if you would like typings for measurements too.

I’ve tested and reviewed these typings and I’m pretty pleased with them. There is room for improvement (for example, the AnalyzerFrame data dict value type would be nice to constrain) but for most stuff I think this will be a lot smoother than checking the docs or other examples.

Please let me know if you have any trouble with this!

typings.zip (4.4 KB)

If you’ve never used typings (pyi) files before, there are two main ways to load them into an IDE like visual studio code.

  1. Automatic loading. VSCode with the standard python extension installed will automatically look for typings in a top-level typings directory. You just need to extract this zip and locate it with nesting such that this file exists: .\typings\saleae\analyzers\__init__.pyi. Restarting VS code after this is a quick, reliable way to make sure this gets picked up.
  2. Put the typings anywhere, and set the .vscode/settings.json key "python.analysis.stubPath" to the directory that holds the “saleae” folder from the zip file above.

Once loading, VS Code type hints look like this: