Skip to main content
Module

x/python/ipy.ts>PythonConvertible

🐍 Python interpreter bindings for Deno and Bun.
Latest
type alias PythonConvertible
import { type PythonConvertible } from "https://deno.land/x/python@0.4.3/ipy.ts";

JS types that can be converted to Python Objects.

  • number becomes int or float depending on its value. If you need to specifically use float or int, use the python.float or python.int classes, like: python.float(42.0). Note that they become PyObjects, not JS values but are still easily passable to Python.

  • bigint currently is casted as number and then transformed to int Python type.

  • null and undefined becomes None in Python. Note that when calling valueOf on PyObject, it is always null.

  • boolean becomes bool in Python.

  • string and Symbol becomes str in Python.

  • Array becomes list in Python.

  • Map and other objects becomes dict in Python. Note that when calling valueOf on PyObject, it is always Map because JS object can only have string keys, while Python dict can have any type.

  • Set becomes set in Python.

  • Callback (custom type) becomes a Python function. First argument passed is an object containing kwargs and rest arguments are positional.

If you pass a PyObject, it is used as-is.

If you pass a PythonProxy, its original PyObject will be used.

definition:
| number
| bigint
| void
| null
| undefined
| boolean
| string
| Symbol
| { [key: string]: PythonConvertible; }