Skip to content

oraichain/jspython-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python ↔ Node SDK (Simple Setup)

Minimal example showing how to call a bundled Node.js RPC file from Python with dynamic methods + autocomplete support.


📁 Project Structure

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.


🚀 Usage

from sdk import NodeSDK
import pathlib

sdk = NodeSDK(str(pathlib.Path(__file__).parent / "sdk.ts"))
print(sdk.add(a=3, b=4))

Output:

7

🧠 How It Works

  1. sdk.py starts:
node sdk.ts
  1. Communication happens over:
stdin / stdout
  1. 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.


✨ Autocomplete & Typing

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.


🔄 Updating Methods

If you add a new method inside sdk.ts:

  1. Rebuild/bundle your Node file.
  2. Regenerate sdk.pyi.
  3. Done.

Python will immediately support the new method with autocomplete.


⚡ Architecture Overview

Python → JSON → stdin → Node → stdout → JSON → Python

Good for:

  • Local tools
  • Wrapping JS libraries
  • Cross-language SDK

✅ Summary

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors