| title | Python |
|---|---|
| description | Use a module from any supported technology in your Python service with Graftcode - no REST wrapper, no rewrite, no custom interop. Install it as a typed Graft and call it like any other dependency. |
Use a module from any supported technology directly in a Python service with Graftcode - no REST wrapper, no rewrite, no custom interop. In this tutorial we use a .NET NuGet module as the example.
- Install a module from another technology as a strongly-typed Graft using
pip- just like any other package. - Configure the generated client to point at the in-memory host.
- Import and call it from your Python code as if it were a native pip package.
- Python installed locally
- .NET SDK (or a
Microsoft.NETCore.Appruntime) installed locally -inMemoryloads this Graft on Netcore, not Node
Create a new folder for your project:
mkdir py-js-module-demo
cd py-js-module-demoFor this example we'll use a .NET sample library from NuGet (sdnTestSimpleCar / SimpleCar), but the same approach works with any module from a supported repository - npm, PyPI, Maven or NuGet.
python -m pip install --extra-index-url https://grft.dev/simple graft-nuget-sdnTestSimpleCar==0.1.0This installs a Graft - a strongly-typed Python client generated from the module. You import and call it like any other pip package, regardless of which technology the module was originally written in.
Set the HYPERTUBE_KEY environment variable in your terminal before running the project:
PowerShell:
$env:HYPERTUBE_KEY="f7GZ-De6k-Mx4p-t7FN-q5DC"Bash (macOS / Linux):
export HYPERTUBE_KEY="f7GZ-De6k-Mx4p-t7FN-q5DC"Windows CMD:
set HYPERTUBE_KEY=f7GZ-De6k-Mx4p-t7FN-q5DCThe first successful activation creates a hypertube.lic file. Later runs (and other local projects) can reuse that license. Activating the same key again in a clean environment may return ERROR:Key already used.
Create main.py:
import os
from graft_nuget_sdntestsimplecar.simple_car import SimpleCar, GraftConfig
GraftConfig.host = "inMemory"
car = SimpleCar("Toyota", "Corolla", 2022, "car-001")
print(car.to_string(), flush=True)
print("Running:", car.is_running, flush=True)
# Now let's call some method!
car.start()
print("Running:", car.is_running, flush=True)
os._exit(0)Run it:
python main.pyThe Python Graft exposes snake_case members (to_string, is_running). Use flush=True before os._exit(0) so printed output is not lost when the process exits.
You should see the car description and running state printed in your terminal. SimpleCar comes from a .NET NuGet package, but your code reads like a regular method call - no HTTP request, no response parsing, no serialization. GraftConfig.host = "inMemory" tells Graftcode to load and execute the .NET assembly inside the same process.
Everything above works without any account - perfect for learning and local development. When you're ready for real-world usage, create a free account at portal.graftcode.com, set up a project, and copy its Project Key.
With a Project Key, point GraftConfig.host at your project's stable registry URL instead of a raw WebSocket address. A Project Key gives you:
- Stable registry URL - the address for your Grafts stays permanent, so install commands don't change when you redeploy.
- Portal visibility - see all your gateways and services in one place at gateways.graftcode.com.
- Access control - decide who can download your Grafts using package manager authentication and permissions.
Using a module from another language in Python typically requires:
- Building a separate service around the module with REST or gRPC endpoints
- Defining request and response DTOs for every operation
- Hosting and deploying that service independently
- Writing HTTP or gRPC client code in your Python project
- Maintaining the integration layer as the module evolves
- Or rewriting the module entirely in Python
- Install any public module from npm, NuGet, or PyPI as a strongly-typed Graft with one command
- Import and call it like a regular Python dependency - no wrappers, no clients
- The module runs in-process or on a remote host, controlled by a single configuration line
Technology choice stops being an integration constraint. You can keep writing Python and use the best libraries from any ecosystem - JavaScript, .NET, Java - as if they were native pip packages.