-
Notifications
You must be signed in to change notification settings - Fork 0
Improve README.md and add REFERENCE.md #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,82 @@ | ||
| # python-node | ||
| # @platformatic/python-node | ||
|
|
||
| Work-in-progress implementation of a Python ASGI server running in Node.js | ||
| via Rust. | ||
| A high-performance Node.js native addon that enables running **ASGI-compatible Python applications** directly within Node.js environments. The Node.js host can communicate directly with the Python guest app without any network involved, allowing near-zero communcation overhead. | ||
|
|
||
| This module provides a bridge between Node.js and Python, allowing you to: | ||
|
|
||
| - **Run Python ASGI applications** (FastAPI, Starlette, Django ASGI, etc.) inside Node.js processes | ||
| - **Handle HTTP requests** with ASGI 3.0 protocol support | ||
| - **Process requests concurrently** using async Python code execution | ||
| - **Integrate Python services** into existing Node.js applications seamlessly | ||
| - **Support virtual environments** automatically for proper Python dependency isolation | ||
|
|
||
| The module implements an ASGI server that translates between Node.js HTTP requests and Python ASGI applications, enabling you to leverage Python's rich ecosystem within Node.js applications. | ||
|
|
||
| ### Key Features | ||
|
|
||
| - **ASGI 3.0 Support**: HTTP and Lifespan protocols (WebSocket support planned) | ||
| - **Async/Sync Methods**: Both `handleRequest()` and `handleRequestSync()` | ||
| - **Virtual Environment Detection**: Automatic Python environment discovery | ||
| - **Cross-Platform**: Native binaries for macOS and Linux | ||
| - **High Performance**: Rust-based implementation with minimal overhead | ||
|
|
||
| ### Requirements | ||
|
|
||
| - **Node.js**: ≥ 20.0.0 | ||
| - **Python**: ≥ 3.8 with asyncio support | ||
| - **System**: macOS (arm64, x64) or Linux (x64-gnu) | ||
|
|
||
| The module automatically detects and uses Python virtual environments via the `VIRTUAL_ENV` environment variable. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @platformatic/python-node | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| For complete API documentation, see [REFERENCE.md](./REFERENCE.md). | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```python | ||
| # fastapi_app.py | ||
| from fastapi import FastAPI | ||
| from pydantic import BaseModel | ||
|
|
||
| app = FastAPI() | ||
|
|
||
| class Item(BaseModel): | ||
| name: str | ||
| price: float | ||
|
|
||
| @app.post("/items/") | ||
| async def create_item(item: Item): | ||
| return {"name": item.name, "price": item.price} | ||
| ``` | ||
|
|
||
| ```javascript | ||
| import { Python, Request } from '@platformatic/python-node' | ||
|
|
||
| const python = new Python({ | ||
| docroot: './python-apps', | ||
| appTarget: 'fastapi_app:app' | ||
| }) | ||
|
|
||
| // POST with JSON body | ||
| const response = await python.handleRequest(new Request({ | ||
| method: 'POST', | ||
| url: '/items/', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: Buffer.from(JSON.stringify({ | ||
| name: 'Widget', | ||
| price: 29.99 | ||
| })) | ||
| })) | ||
|
|
||
| const result = JSON.parse(response.body.toString()) | ||
| console.log(result) // { name: 'Widget', price: 29.99 } | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.