Skip to main content

Embed Node.js natively in your Python code.

Project description

pythonodejs 🐍➕🟢

PyPI version Python versions License: MIT Downloads

Embed Node.js natively in Python with seamless integration.

📋 Overview

pythonodejs lets you harness the power of the Node.js ecosystem directly within your Python applications. Run JavaScript code, use NPM packages, and leverage the best of both worlds in a single application.

🚀 Installation

pip install pythonodejs

🔍 Quick Example

from pythonodejs import node_eval

# Execute JavaScript directly
node_eval("console.log('Hello from Node.js in Python!')")
# > Hello from Node.js in Python!

# Create and return JavaScript functions
read_file = node_eval("""
const fs = require('fs');

function readFile(filePath) {
    return fs.readFileSync(filePath, 'utf8');
}

readFile; // Return the function
""")

# Call JavaScript functions from Python
content = read_file("example.txt")
print(content)
More Examples

🔄 Integration with NPM

npm init -y
npm install lodash express axios
from pythonodejs import node_eval

result = node_eval("""
const _ = require('lodash');
const numbers = [1, 2, 3, 4, 5];
_.sum(numbers);
""")
print(f"Sum: {result}")

node_eval("""
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello from Express running in Python!');
});

app.listen(3000, () => {
  console.log('Express server running on port 3000');
});
""")

🔧 Advanced Usage

Working with JS Objects

person = node_eval("""
const person = {
  name: 'John',
  age: 30,
  greet: function() {
    return `Hello, my name is ${this.name}`;
  }
};
person;
""")
print(person['name'])
print(person['greet']())

Passing Python → JS

process_data = node_eval("""
function processData(data) {
  return {
    processed: true,
    items: data.items.map(x => x * 2),
    message: `Processed ${data.items.length} items`
  };
}
processData;
""")

result = process_data({'items': [1, 2, 3, 4, 5]})
print(result)

✅ ToDo

  • Stable release
  • Loading ES Modules
  • Automatic npm install on dependency detection
  • Better error logging

🏗️ Building from Source

  1. Install SConstruct and Clang
  2. Run pip install -r requirements.txt
  3. Run scons

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT License.

🙏 Special Thanks

A special thanks to M-logique for their contribution to this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pythonodejs-1.4.6-cp312-cp312-win_amd64.whl (35.7 MB view details)

Uploaded CPython 3.12Windows x86-64

pythonodejs-1.4.6-cp312-cp312-macosx_14_0_arm64.whl (102.8 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pythonodejs-1.4.6-cp311-cp311-win_amd64.whl (35.7 MB view details)

Uploaded CPython 3.11Windows x86-64

pythonodejs-1.4.6-cp311-cp311-macosx_14_0_arm64.whl (102.8 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pythonodejs-1.4.6-cp310-cp310-win_amd64.whl (35.7 MB view details)

Uploaded CPython 3.10Windows x86-64

pythonodejs-1.4.6-cp310-cp310-macosx_14_0_arm64.whl (102.8 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

pythonodejs-1.4.6-cp39-cp39-win_amd64.whl (35.7 MB view details)

Uploaded CPython 3.9Windows x86-64

pythonodejs-1.4.6-cp39-cp39-macosx_14_0_arm64.whl (102.8 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file pythonodejs-1.4.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bb6a50315bb9b149778e0fc5e2249f3164432e2eeceefb023636d1e4462a7995
MD5 a3ea8540d94f548e529685b04e5469ca
BLAKE2b-256 cc804296ac287aa09bf71c4809b94cd813223926e92db5ab9eba3ed548afc92f

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 945d17a423ff398ee9265a380df98d279a3cd4c8df8ec3f8a08f2e8a14f41d4f
MD5 5d2efc8cc8d2431ced587de37700fe0e
BLAKE2b-256 e7c5f02aa5dd200d429fa270fa7ff95b2c991bbcd90c14a92ebc2994cd2ab748

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0c3377b03b33cdf24861397ed6e9c06446015aab3e692f12de6fdcef2249e69f
MD5 2f3c34457ad3acaf9c52a0670047eaeb
BLAKE2b-256 5e6a77a3d4b34c373742d98d38262e09a800615879423073a1609019daed4d56

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 babe84e4fe47ff0f6a45253c6a2fdab1fdca6c6e18e10f5f40c32c5257fa3036
MD5 4b64cc33e025e0ddea1d1261fb0da92c
BLAKE2b-256 8ed6a33e33aa9f6653a0e6d52e3795671a3aa35cbf821db53273e12a1fb80f31

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 79827062aed54584e4c3063a1af04b2125604179ba494c57331606c0b6e8c2cb
MD5 ea9bd111c2d9e5e5b62c81f6ccdfee43
BLAKE2b-256 fc566e01bcf4ba4c46121ee29a4b77f46cc5abe10dc05308ee79b5155719a65d

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9f44824381d217eb27c266de31fc1dcb72187815f71952492b07e6eb9ebf5e0a
MD5 8a996b90602b6ba1a184a2514741a13f
BLAKE2b-256 4309c9d8659e2487e62034044add40ae0f387fd9c51e22a36e4c606e128bac5b

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pythonodejs-1.4.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 35.7 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for pythonodejs-1.4.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 08afd083aa234714d05cd9804b135842411f5d6161f03eb5a99c739febf75a83
MD5 0e14500fa93aed9fba1fadd5d604342d
BLAKE2b-256 b6b41ef5706efee61a22d02e341c7548bf62e5b0344021784a811e8f07f3e4db

See more details on using hashes here.

File details

Details for the file pythonodejs-1.4.6-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pythonodejs-1.4.6-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 35ceee3240a637416d4637d368d561bda6eea58b464e86c06435413b5a653bbd
MD5 c87abac1f7ce22a96fdc01b5e177a091
BLAKE2b-256 755483b699da23554e33ffcca0fd15d3c86e8861e6baea584ab42e222f9da074

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page