Minimal example showing how to call a bundled Node.js RPC file from Python with dynamic methods + autocomplete support.
project/
├─ sdk.py # Python runtime client
├─ sdk.pyi # Auto-generated typing stub
└─ sdk.ts # Bundled Node RPC file
That’s it. Flat structure. No subfolders.
from sdk import NodeSDK
import pathlib
sdk = NodeSDK(str(pathlib.Path(__file__).parent / "sdk.ts"))
print(sdk.add(a=3, b=4))Output:
7
sdk.pystarts:
node sdk.ts
- Communication happens over:
stdin / stdout
- Python dynamically exposes methods using:
def __getattr__(self, name):So any RPC method defined in sdk.ts becomes callable:
sdk.add(...)
sdk.multiply(...)
sdk.greet(...)No wrapper functions needed.
sdk.pyi provides type hints for editors (VSCode, PyCharm, etc).
Example:
class NodeSDK:
def add(self, *, a: float, b: float) -> float: ...The runtime is dynamic.
The .pyi file is only for type checking and autocomplete.
If you add a new method inside sdk.ts:
- Rebuild/bundle your Node file.
- Regenerate
sdk.pyi. - Done.
Python will immediately support the new method with autocomplete.
Python → JSON → stdin → Node → stdout → JSON → Python
Good for:
- Local tools
- Wrapping JS libraries
- Cross-language SDK
This setup gives you:
- JS logic in
sdk.ts - Python interface in
sdk.py - Autocomplete via
sdk.pyi - No duplicated wrapper code
- Clean and simple structure
Minimal files. Clean workflow. Easy to extend.