dartpy library Null safety
Darpy is a library that allows dart to call out to python code
For a simple python script inline you can do the following:
void main(List<String> args) {
dartpyc.Py_Initialize();
final python = '''
from time import time, ctime
print("Today is", ctime(time()))
''';
final pystring = python.toNativeUtf8();
dartpyc.PyRun_SimpleString(pystring.cast<Int8>());
malloc.free(pystring);
print(dartpyc.Py_FinalizeEx());
}
For a more complex script that you don't want inline you can do this:
void main() {
// initializes the python runtime
pyStart();
try {
// imports a python module
final pyModule = pyimport('multiply');
// gets a function within that module
final pFunc = pyModule.getFunction('multiply');
// calls the function and gets the result
final result = pFunc([1, 2]);
print(result); // Should print 3
} on DartPyException catch (e) {
print(e);
// Cleans up memory
pyCleanup();
exit(1);
}
// Cleans up memory
pyCleanup();
exit(0);
}
Classes
- ArrayHelper__longobject_ob_digit_level0
-
Helper for array
ob_digit
in struct_longobject
. - ArrayHelper__PyBytesWriter_small_buffer_level0
-
Helper for array
small_buffer
in struct_PyBytesWriter
. - ArrayHelper_FILE__shortbuf_level0
-
Helper for array
_shortbuf
in structFILE
. - ArrayHelper_FILE__unused2_level0
-
Helper for array
_unused2
in structFILE
. - ArrayHelper_PyBytesObject_ob_sval_level0
-
Helper for array
ob_sval
in structPyBytesObject
. - ArrayHelper_PyMemoryViewObject_ob_array_level0
-
Helper for array
ob_array
in structPyMemoryViewObject
. - ArrayHelper_PySetObject_smalltable_level0
-
Helper for array
smalltable
in structPySetObject
. - ArrayHelper_stat___glibc_reserved_level0
-
Helper for array
__glibc_reserved
in structstat
. - DartPyC
- Bindings to Python C interface
- DartPyFunction
- A dart representation of a python function
- DartPyModule
- A dart representation for the python module
- FILE
- Py_buffer
- Py_complex
- Py_error_handler
- PyAddrPair
- PyAsyncGenObject
- PyAsyncMethods
- PyBufferProcs
- PyByteArrayObject
- PyBytesObject
- PyCellObject
- PyCFunctionObject
- PyCodeObject
- PyCompilerFlags
- PyComplexObject
- PyCoroObject
- PyDescrObject
- PyFloatObject
- PyFunctionObject
- PyFutureFeatures
- PyGenObject
- PyGetSetDef
- PyGetSetDescrObject
- PyGILState_STATE
- PyHash_FuncDef
- PyInstanceMethodObject
- PyListObject
- PyLockStatus
- PyMappingMethods
- PyMemberDef
- PyMemberDescrObject
- PyMemoryViewObject
- PyMethodDef
- PyMethodDescrObject
- PyMethodObject
- PyModuleDef
- PyModuleDef_Base
- PyModuleDef_Slot
- PyNumberMethods
- PyObject
- PySequenceMethods
- PySetObject
- PySliceObject
- PyStructSequence_Desc
- PyStructSequence_Field
- PyTime_round_t
- PyType_Slot
- PyType_Spec
- PyVarObject
- PyWrapperDescrObject
- setentry
- stat
- symtable
- timespec
- timeval
- tm
- wrapperbase
Extensions
Constants
- CO_ASYNC_GENERATOR → const int
-
512
- CO_CELL_NOT_AN_ARG → const int
-
-1
- CO_COROUTINE → const int
-
128
- CO_FUTURE_ABSOLUTE_IMPORT → const int
-
16384
- CO_FUTURE_ANNOTATIONS → const int
-
1048576
- CO_FUTURE_BARRY_AS_BDFL → const int
-
262144
- CO_FUTURE_DIVISION → const int
-
8192
- CO_FUTURE_GENERATOR_STOP → const int
-
524288
- CO_FUTURE_PRINT_FUNCTION → const int
-
65536
- CO_FUTURE_UNICODE_LITERALS → const int
-
131072
- CO_FUTURE_WITH_STATEMENT → const int
-
32768
- CO_GENERATOR → const int
-
32
- CO_ITERABLE_COROUTINE → const int
-
256
- CO_MAXBLOCKS → const int
-
20
- CO_NESTED → const int
-
16
- CO_NEWLOCALS → const int
-
2
- CO_NOFREE → const int
-
64
- CO_OPTIMIZED → const int
-
1
- CO_VARARGS → const int
-
4
- CO_VARKEYWORDS → const int
-
8
- F_ALT → const int
-
8
- F_BLANK → const int
-
4
- F_LJUST → const int
-
1
- F_SIGN → const int
-
2
- F_ZERO → const int
-
16
- FUTURE_ABSOLUTE_IMPORT → const String
-
'absolute_import'
- FUTURE_ANNOTATIONS → const String
-
'annotations'
- FUTURE_BARRY_AS_BDFL → const String
-
'barry_as_FLUFL'
- FUTURE_DIVISION → const String
-
'division'
- FUTURE_GENERATOR_STOP → const String
-
'generator_stop'
- FUTURE_GENERATORS → const String
-
'generators'
- FUTURE_NESTED_SCOPES → const String
-
'nested_scopes'
- FUTURE_PRINT_FUNCTION → const String
-
'print_function'
- FUTURE_UNICODE_LITERALS → const String
-
'unicode_literals'
- FUTURE_WITH_STATEMENT → const String
-
'with_statement'
- FVC_ASCII → const int
-
3
- FVC_MASK → const int
-
3
- FVC_NONE → const int
-
0
- FVC_REPR → const int
-
2
- FVC_STR → const int
-
1
- FVS_HAVE_SPEC → const int
-
4
- FVS_MASK → const int
-
4
- HAVE_LONG_LONG → const int
-
1
- HAVE_PY_SET_53BIT_PRECISION → const int
-
1
- MAX_CO_EXTRA_USERS → const int
-
255
- METH_CLASS → const int
-
16
- METH_COEXIST → const int
-
64
- METH_FASTCALL → const int
-
128
- METH_KEYWORDS → const int
-
2
- METH_NOARGS → const int
-
4
- METH_O → const int
-
8
- METH_STACKLESS → const int
-
0
- METH_STATIC → const int
-
32
- METH_VARARGS → const int
-
1
- NOWAIT_LOCK → const int
-
0
- Py_am_aiter → const int
-
78
- Py_am_anext → const int
-
79
- Py_am_await → const int
-
77
- PY_BIG_ENDIAN → const int
-
0
- Py_CLEANUP_SUPPORTED → const int
-
131072
- PY_CTF_ALNUM → const int
-
7
- PY_CTF_ALPHA → const int
-
3
- PY_CTF_DIGIT → const int
-
4
- PY_CTF_LOWER → const int
-
1
- PY_CTF_SPACE → const int
-
8
- PY_CTF_UPPER → const int
-
2
- PY_CTF_XDIGIT → const int
-
16
- Py_DTSF_ADD_DOT_0 → const int
-
2
- Py_DTSF_ALT → const int
-
4
- Py_DTSF_SIGN → const int
-
1
- Py_DTST_FINITE → const int
-
0
- Py_DTST_INFINITE → const int
-
1
- Py_DTST_NAN → const int
-
2
- PY_DWORD_MAX → const int
-
4294967295
- Py_EQ → const int
-
2
- Py_eval_input → const int
-
258
- Py_file_input → const int
-
257
- Py_func_type_input → const int
-
345
- Py_GE → const int
-
5
- Py_GT → const int
-
4
- Py_HASH_ALGORITHM → const int
-
1
- Py_HASH_CUTOFF → const int
-
0
- Py_HASH_EXTERNAL → const int
-
0
- Py_HASH_FNV → const int
-
2
- Py_HASH_SIPHASH24 → const int
-
1
- Py_HUGE_VAL → const double
-
double.infinity
- Py_INVALID_SIZE → const int
-
-1
- PY_INVALID_STACK_EFFECT → const int
-
2147483647
- Py_LE → const int
-
1
- PY_LITTLE_ENDIAN → const int
-
1
- PY_LLONG_MAX → const int
-
9223372036854775807
- PY_LLONG_MIN → const int
-
-9223372036854775808
- Py_LT → const int
-
0
- PY_MAJOR_VERSION → const int
-
3
- Py_MATH_E → const double
-
2.718281828459045
- Py_MATH_El → const double
-
2.718281828459045
- Py_MATH_PI → const double
-
3.141592653589793
- Py_MATH_PIl → const double
-
3.141592653589793
- Py_MATH_TAU → const double
-
6.283185307179586
- PY_MICRO_VERSION → const int
-
0
- PY_MINOR_VERSION → const int
-
8
- Py_mod_create → const int
-
1
- Py_mod_exec → const int
-
2
- Py_mp_ass_subscript → const int
-
3
- Py_mp_length → const int
-
4
- Py_mp_subscript → const int
-
5
- Py_NAN → const double
-
double.nan
- Py_nb_absolute → const int
-
6
- Py_nb_add → const int
-
7
- Py_nb_and → const int
-
8
- Py_nb_bool → const int
-
9
- Py_nb_divmod → const int
-
10
- Py_nb_float → const int
-
11
- Py_nb_floor_divide → const int
-
12
- Py_nb_index → const int
-
13
- Py_nb_inplace_add → const int
-
14
- Py_nb_inplace_and → const int
-
15
- Py_nb_inplace_floor_divide → const int
-
16
- Py_nb_inplace_lshift → const int
-
17
- Py_nb_inplace_matrix_multiply → const int
-
76
- Py_nb_inplace_multiply → const int
-
18
- Py_nb_inplace_or → const int
-
19
- Py_nb_inplace_power → const int
-
20
- Py_nb_inplace_remainder → const int
-
21
- Py_nb_inplace_rshift → const int
-
22
- Py_nb_inplace_subtract → const int
-
23
- Py_nb_inplace_true_divide → const int
-
24
- Py_nb_inplace_xor → const int
-
25
- Py_nb_int → const int
-
26
- Py_nb_invert → const int
-
27
- Py_nb_lshift → const int
-
28
- Py_nb_matrix_multiply → const int
-
75
- Py_nb_multiply → const int
-
29
- Py_nb_negative → const int
-
30
- Py_nb_or → const int
-
31
- Py_nb_positive → const int
-
32
- Py_nb_power → const int
-
33
- Py_nb_remainder → const int
-
34
- Py_nb_rshift → const int
-
35
- Py_nb_subtract → const int
-
36
- Py_nb_true_divide → const int
-
37
- Py_nb_xor → const int
-
38
- Py_NE → const int
-
3
- Py_PRINT_RAW → const int
-
1
- PY_RELEASE_LEVEL → const int
-
15
- PY_RELEASE_LEVEL_ALPHA → const int
-
10
- PY_RELEASE_LEVEL_BETA → const int
-
11
- PY_RELEASE_LEVEL_FINAL → const int
-
15
- PY_RELEASE_LEVEL_GAMMA → const int
-
12
- PY_RELEASE_SERIAL → const int
-
0
- Py_single_input → const int
-
256
- PY_SIZE_MAX → const int
-
-1
- Py_sq_ass_item → const int
-
39
- Py_sq_concat → const int
-
40
- Py_sq_contains → const int
-
41
- Py_sq_inplace_concat → const int
-
42
- Py_sq_inplace_repeat → const int
-
43
- Py_sq_item → const int
-
44
- Py_sq_length → const int
-
45
- Py_sq_repeat → const int
-
46
- PY_SSIZE_T_MAX → const int
-
9223372036854775807
- PY_SSIZE_T_MIN → const int
-
-9223372036854775808
- PY_STDIOTEXTMODE → const String
-
'b'
- PY_TIMEOUT_MAX → const int
-
9223372036854775
- Py_tp_alloc → const int
-
47
- Py_tp_base → const int
-
48
- Py_tp_bases → const int
-
49
- Py_tp_call → const int
-
50
- Py_tp_clear → const int
-
51
- Py_tp_dealloc → const int
-
52
- Py_tp_del → const int
-
53
- Py_tp_descr_get → const int
-
54
- Py_tp_descr_set → const int
-
55
- Py_tp_doc → const int
-
56
- Py_tp_finalize → const int
-
80
- Py_tp_free → const int
-
74
- Py_tp_getattr → const int
-
57
- Py_tp_getattro → const int
-
58
- Py_tp_getset → const int
-
73
- Py_tp_hash → const int
-
59
- Py_tp_init → const int
-
60
- Py_tp_is_gc → const int
-
61
- Py_tp_iter → const int
-
62
- Py_tp_iternext → const int
-
63
- Py_tp_members → const int
-
72
- Py_tp_methods → const int
-
64
- Py_tp_new → const int
-
65
- Py_tp_repr → const int
-
66
- Py_tp_richcompare → const int
-
67
- Py_tp_setattr → const int
-
68
- Py_tp_setattro → const int
-
69
- Py_tp_str → const int
-
70
- Py_tp_traverse → const int
-
71
- Py_TPFLAGS_BASE_EXC_SUBCLASS → const int
-
1073741824
- Py_TPFLAGS_BASETYPE → const int
-
1024
- Py_TPFLAGS_BYTES_SUBCLASS → const int
-
134217728
- Py_TPFLAGS_DEFAULT → const int
-
262144
- Py_TPFLAGS_DICT_SUBCLASS → const int
-
536870912
- Py_TPFLAGS_HAVE_FINALIZE → const int
-
1
- Py_TPFLAGS_HAVE_GC → const int
-
16384
- Py_TPFLAGS_HAVE_STACKLESS_EXTENSION → const int
-
0
- Py_TPFLAGS_HAVE_VERSION_TAG → const int
-
262144
- Py_TPFLAGS_HEAPTYPE → const int
-
512
- Py_TPFLAGS_IS_ABSTRACT → const int
-
1048576
- Py_TPFLAGS_LIST_SUBCLASS → const int
-
33554432
- Py_TPFLAGS_LONG_SUBCLASS → const int
-
16777216
- Py_TPFLAGS_METHOD_DESCRIPTOR → const int
-
131072
- Py_TPFLAGS_READY → const int
-
4096
- Py_TPFLAGS_READYING → const int
-
8192
- Py_TPFLAGS_TUPLE_SUBCLASS → const int
-
67108864
- Py_TPFLAGS_TYPE_SUBCLASS → const int
-
2147483648
- Py_TPFLAGS_UNICODE_SUBCLASS → const int
-
268435456
- Py_TPFLAGS_VALID_VERSION_TAG → const int
-
524288
- PY_ULLONG_MAX → const int
-
-1
- Py_UNICODE_REPLACEMENT_CHARACTER → const int
-
65533
- Py_UNICODE_SIZE → const int
-
4
- PY_VERSION → const String
-
'3.8.0'
- PY_VERSION_HEX → const int
-
50856176
- PyCF_ALLOW_TOP_LEVEL_AWAIT → const int
-
8192
- PyCF_DONT_IMPLY_DEDENT → const int
-
512
- PyCF_IGNORE_COOKIE → const int
-
2048
- PyCF_MASK → const int
-
2088960
- PyCF_MASK_OBSOLETE → const int
-
16
- PyCF_ONLY_AST → const int
-
1024
- PyCF_SOURCE_IS_UTF8 → const int
-
256
- PyCF_TYPE_COMMENTS → const int
-
4096
- PyLong_BASE → const int
-
1073741824
- PYLONG_BITS_IN_DIGIT → const int
-
30
- PyLong_MASK → const int
-
1073741823
- PyLong_SHIFT → const int
-
30
- PYOS_STACK_MARGIN → const int
-
2048
- PySet_MINSIZE → const int
-
8
- PYTHON_ABI_STRING → const String
-
'3'
- PYTHON_ABI_VERSION → const int
-
3
- PYTHON_API_STRING → const String
-
'1013'
- PYTHON_API_VERSION → const int
-
1013
- PYTHREAD_INVALID_THREAD_ID → const int
-
-1
- PyTrash_UNWIND_LEVEL → const int
-
50
- PyWrapperFlag_KEYWORDS → const int
-
1
- SIZEOF_PY_HASH_T → const int
-
8
- SIZEOF_PY_UHASH_T → const int
-
8
- WAIT_LOCK → const int
-
1
Properties
- dartpyc → DartPyC
-
Dynamic library
read-only
- pyInitialized → bool
-
Checks whether the python runtime was initialized
read-only
- pyLibLocation ↔ String?
-
A variable to override the python dynamic library location on your computer
read / write
Functions
-
pyCleanup(
) → void - Cleans up the memory of the loaded modules
-
pyConvertBackDouble(
Pointer< PyObject> o) → double - Converts a python double to a dart double
-
pyConvertBackDynamic(
Pointer< PyObject> result) → Object? - Convers a python object back to a dart representation
-
pyConvertBackInt(
Pointer< PyObject> o) → int - Converts a python int to a dart int
-
pyConvertBackNum(
Pointer< PyObject> o) → num - Converts a python int or double to a dart number
-
pyConvertDouble(
double o) → Pointer< PyObject> - Converts a double to a python double
-
pyConvertDynamic(
Object? o) → Pointer< PyObject> - Converts a Dart object to the python equivalent [...]
-
pyConvertInt(
int o) → Pointer< PyObject> - Converts an int to a python int
-
pyConvertNum(
num o) → Pointer< PyObject> - Converts a num to a python int or double
-
pyErrOccurred(
) → bool - Checks whether an exception occured in python
-
pyimport(
String module) → DartPyModule - Loads a python module
-
pyIsBool(
Pointer< PyObject> object) → bool -
Checks whether
object
is a boolean -
pyIsCallable(
Pointer< PyObject> object) → bool -
Checks whether
object
is callable -
pyStart(
) → void - Initializes the python runtime
Typedefs
-
allocfunc(
Pointer< _typeobject> , Int64) → Pointer<PyObject> -
binaryfunc(
Pointer< PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
descrgetfunc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
descrsetfunc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Int32 -
destructor(
Pointer< PyObject> ) → Void -
freefunc(
Pointer< Void> ) → Void -
getattrfunc(
Pointer< PyObject> , Pointer<Int8> ) → Pointer<PyObject> -
getattrofunc(
Pointer< PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
getbufferproc(
Pointer< PyObject> , Pointer<Py_buffer> , Int32) → Int32 -
getiterfunc(
Pointer< PyObject> ) → Pointer<PyObject> -
getter(
Pointer< PyObject> , Pointer<Void> ) → Pointer<PyObject> -
hashfunc(
Pointer< PyObject> ) → Int64 -
initproc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Int32 -
inquiry(
Pointer< PyObject> ) → Int32 -
iternextfunc(
Pointer< PyObject> ) → Pointer<PyObject> -
lenfunc(
Pointer< PyObject> ) → Int64 -
newfunc(
Pointer< _typeobject> , Pointer<PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
objobjargproc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Int32 -
objobjproc(
Pointer< PyObject> , Pointer<PyObject> ) → Int32 -
Py_tracefunc(
Pointer< PyObject> , Pointer<_frame> , Int32, Pointer<PyObject> ) → Int32 -
PyCapsule_Destructor(
Pointer< PyObject> ) → Void -
PyCFunction(
Pointer< PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
PyOS_sighandler_t(
Int32) → Void -
releasebufferproc(
Pointer< PyObject> , Pointer<Py_buffer> ) → Void -
reprfunc(
Pointer< PyObject> ) → Pointer<PyObject> -
richcmpfunc(
Pointer< PyObject> , Pointer<PyObject> , Int32) → Pointer<PyObject> -
setattrfunc(
Pointer< PyObject> , Pointer<Int8> , Pointer<PyObject> ) → Int32 -
setattrofunc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Int32 -
setter(
Pointer< PyObject> , Pointer<PyObject> , Pointer<Void> ) → Int32 -
ssizeargfunc(
Pointer< PyObject> , Int64) → Pointer<PyObject> -
ssizeobjargproc(
Pointer< PyObject> , Int64, Pointer<PyObject> ) → Int32 -
ternaryfunc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<PyObject> ) → Pointer<PyObject> -
traverseproc(
Pointer< PyObject> , Pointer<NativeFunction< , Pointer<visitproc> >Void> ) → Int32 -
unaryfunc(
Pointer< PyObject> ) → Pointer<PyObject> -
vectorcallfunc(
Pointer< PyObject> , Pointer<Pointer< , Uint64, Pointer<PyObject> >PyObject> ) → Pointer<PyObject> -
visitproc(
Pointer< PyObject> , Pointer<Void> ) → Int32 -
wrapperfunc(
Pointer< PyObject> , Pointer<PyObject> , Pointer<Void> ) → Pointer<PyObject>
Exceptions / Errors
- DartPyException
- A dart exception wrapping a python exception