std.ffi.python Package
Function Description
The ffi.python package provides the interoperability between Cangjie and Python to be compatible with powerful computing and AI ecosystems.
This package:
-
Provides a global interpreter object
Python
of thePythonBuiltins
type, which can be used to:- Load and unload interpreter resources.
- Obtain the version of the Python interpreter in use.
- Import and use third-party modules of Python.
For the detailed description and use of this package, see Cangjie Programming Language Developer Guide (Cross-Language Interoperability/Interoperability with Python/PythonBuiltins Class).
-
Provides the conversion between Python data types and Cangjie data types. For example, PyBool, PyLong, PyFloat, PyString, PyTuple, PyList, PyDict, and PySet are inherited from the
PyObject
type. ThePyObject
type provides universal interfaces for all types, such as member variable access, function access, and conversion to Cangjie types. The subclasses of thePyObject
type provide function interfaces specific to each type.For the detailed description and use of the mapping relationship, see Cangjie Programming Language Developer Guide (Cross-Language Interoperability/Interoperability with Python/Type Mapping).
-
Supports simple function registration and Python's callback of Cangjie functions. Python calls back the Cangjie code through C language and using its third-party libraries,
ctypes
and_ctypes
.For the detailed description and use of the mapping relationship, see Cangjie Programming Language Developer Guide (Cross-Language Interoperability/Interoperability with Python/Callback Registration of Cangjie and Python). This section describes the type mapping between parameters and return values for callback, as well as the calling methods.
Note:
- This package is not supported on Windows.
API List
Constants and Variables
Name | Description |
---|---|
PYLOG | Specifies the ffi.python log object, which is used for printing control and output. |
Python | Specifies the global resource of the Python interpreter. |
Interface
Name | Description |
---|---|
CjObj | Provides a function for converting a Cangjie type to a Python Object type. |
PyFFIType | Indicates the type that supports interoperability with Python. |
Class
Name | Description |
---|---|
PyBool | Indicates the Boolean type of Python. |
PyCFunc | Indicates the C-style function type of Python. |
PyDict<K, V> where K <: Hashable & Equatable<K> & PyFFIType | Indicates the dictionary type of Python. |
PyFloat | Indicates the floating-point number type of Python. |
PyList<T> where T <: PyFFIType | Indicates the list type of Python. |
PyLong | Indicates the integer type of Python. |
PyObj | Indicates the parent class of all Python types. |
PyObjIterator | Indicates the iterator type of PyObj . |
PyString | Indicates the string type of Python. |
PySet<T> where T <: Hashable & Equatable<T> & PyFFIType | Indicates the set type of Python. |
PySlice<T> where T <: Countable<T> & Comparable<T> & Equatable<T> & CjObj | Indicates the interval type of Python. |
PyTuple | Indicates the tuple type of Python. |
PythonLogger | Indicates the log type of the ffi.python package. |
PythonBuiltins | Indicates the built-in function set of Python. |
Exception Class
Name | Description |
---|---|
PythonException | Indicates the exception type from the ffi.python package. |