MIT License

项目介绍

denosaurs/deno_python 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 757 个 Star、27 次 Fork。

仓库全名
denosaurs/deno_python
开源许可证
MIT License
Star 数
757
Fork 数
27
未关闭 Issue
17

README 摘要

Python Bridge This module provides a seamless integration between JavaScript (Deno/Bun) and Python by integrating with the Python/C API. It acts as a bridge between the two languages, enabling you to pass data and execute python code from within your JS applications. This enables access to the large and wonderful python ecosystem while remaining native (unlike a runtime like the wonderful pyodide which is compiled…

完整内容见 GitHub 原始 README 或本页 。

常见问题

deno_python 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 757 个 Star。

deno_python 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 deno_python 的源码?

可以直接克隆仓库:git clone https://github.com/denosaurs/deno_python.git,默认分支为 main;安装与运行步骤见仓库 README。

deno_python 最近还在维护吗?

仓库最近一次更新为 9月16日,当前有 17 个未关闭 Issue;Star 数为 757,可作为社区活跃度的参考。

关于

🐍 Python interpreter bindings for Deno and Bun.

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
819
价值分
462
活跃状态
活跃

语言占比

JavaScript
TypeScript

Release

README

Python Bridge

Tags deno doc checks License

This module provides a seamless integration between JavaScript (Deno/Bun) and Python by integrating with the Python/C API. It acts as a bridge between the two languages, enabling you to pass data and execute python code from within your JS applications. This enables access to the large and wonderful python ecosystem while remaining native (unlike a runtime like the wonderful pyodide which is compiled to wasm, sandboxed and may not work with all python packages) and simply using the existing python installation.

Example

Import any locally installed Python package, for example, matplotlib:

import { python } from "https://deno.land/x/python/mod.ts";

const np = python.import("numpy");
const plt = python.import("matplotlib.pyplot");

const xpoints = np.array([1, 8]);
const ypoints = np.array([3, 10]);

plt.plot(xpoints, ypoints);
plt.show();

When running, you must specify --allow-ffi, --allow-env and --unstable-ffi flags. Alternatively, you may also just specify -A instead of specific permissions since enabling FFI effectively escapes the permissions sandbox.

deno run -A --unstable-ffi <file>

Usage in Bun

You can import from the bunpy NPM package to use this module in Bun.

import { python } from "bunpy";

const np = python.import("numpy");
const plt = python.import("matplotlib.pyplot");

const xpoints = np.array([1, 8]);
const ypoints = np.array([3, 10]);

plt.plot(xpoints, ypoints);
plt.show();

Dependencies

Normally deno_python follows the default python way of resolving imports, going through sys.path resolving them globally, locally or scoped to a virtual environment. This is great and allows you to manage your python dependencies for deno_python projects in the same way you would any other python project using your favorite package manager, be it pip, conda or poetry.

This may not be a good thing though, especially for something like a deno module which may depend on a python package. That is why the ext/pip utility exists for this project. It allows you to install python dependencies using pip, scoped to either the global deno installation or if defined the --location passed to deno without leaking to the global python scope. It uses the same caching location and algorithm as plug and deno cache.

To use ext/pip for python package management you simply use the provided import or install methods. The rest is handled automatically for you! Just take a look!

import { pip } from "https://deno.land/x/python/ext/pip.ts";

const np = await pip.import("numpy");
const plt = await pip.import("matplotlib", "matplotlib.pyplot");

const xpoints = np.array([1, 8]);
const ypoints = np.array([3, 10]);

plt.plot(xpoints, ypoints);
plt.show();

Documentation

Check out the docs here.

Python Installation

This module uses FFI to interface with the Python interpreter’s C API. So you must have an existing Python installation (with the shared library), which is something like python310.dll, etc.

Python installed from Microsoft Store does not work, as it does not contain shared library for interfacing with Python interpreter.

If the module fails to find Python, you can add the path to the Python in the DENO_PYTHON_PATH environment variable.

DENO_PYTHON_PATH if set, must point to full path including the file name of the Python dynamic library, which is like python310.dll (Windows), libpython310.dylib (macOS) and libpython310.so (Linux) depending on platform.

Usage with docker

Usage with docker is easiest done using the denoland/deno:bin image along with the official python image.

ARG DENO_VERSION=1.38.2
ARG PYTHON_VERSION=3.12

FROM denoland/deno:bin-$DENO_VERSION AS deno
FROM python:$PYTHON_VERSION

# Copy and configure deno
COPY --from=deno /deno /usr/local/bin/deno
ENTRYPOINT ["/usr/local/bin/deno"]

# Copy your project source
COPY . .

RUN ["run", "-A", "--unstable", "https://deno.land/x/[email protected]/examples/hello_python.ts"]

Maintainers

Other

Contribution

Pull request, issues and feedback are very welcome. Code style is formatted with deno fmt and commit messages are done following Conventional Commits spec.

Licence

Copyright 2021, DjDeveloperr.

Copyright 2023, the Denosaurs team. All rights reserved. MIT license.

评论

暂无评论