It seems that Pyright (the Python type checker made by Microsoft) can only be used as a command line tool or from VS Code. But is it possible to call pyright from code (as an API)?
For example, mypy supports usage like:
import sys
from mypy import api
result = api.run("your code")
like @Grismar said, this might be an xy problem... if not, here is a general solution:
import subprocess
command = ['pyright', 'path/to/your/file.py']
result = subprocess.run(command, capture_output=True, text=True)
output = result.stdout
print(output)