nodepyx 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +399 -0
  3. package/binding.gyp +73 -0
  4. package/dist/core/PyCallable.d.ts +65 -0
  5. package/dist/core/PyCallable.d.ts.map +1 -0
  6. package/dist/core/PyCallable.js +109 -0
  7. package/dist/core/PyCallable.js.map +1 -0
  8. package/dist/core/PyContext.d.ts +76 -0
  9. package/dist/core/PyContext.d.ts.map +1 -0
  10. package/dist/core/PyContext.js +228 -0
  11. package/dist/core/PyContext.js.map +1 -0
  12. package/dist/core/PyIterator.d.ts +84 -0
  13. package/dist/core/PyIterator.d.ts.map +1 -0
  14. package/dist/core/PyIterator.js +243 -0
  15. package/dist/core/PyIterator.js.map +1 -0
  16. package/dist/core/PyModule.d.ts +55 -0
  17. package/dist/core/PyModule.d.ts.map +1 -0
  18. package/dist/core/PyModule.js +172 -0
  19. package/dist/core/PyModule.js.map +1 -0
  20. package/dist/core/PyProxy.d.ts +65 -0
  21. package/dist/core/PyProxy.d.ts.map +1 -0
  22. package/dist/core/PyProxy.js +483 -0
  23. package/dist/core/PyProxy.js.map +1 -0
  24. package/dist/core/PyRuntime.d.ts +105 -0
  25. package/dist/core/PyRuntime.d.ts.map +1 -0
  26. package/dist/core/PyRuntime.js +438 -0
  27. package/dist/core/PyRuntime.js.map +1 -0
  28. package/dist/env/CondaManager.d.ts +118 -0
  29. package/dist/env/CondaManager.d.ts.map +1 -0
  30. package/dist/env/CondaManager.js +401 -0
  31. package/dist/env/CondaManager.js.map +1 -0
  32. package/dist/env/PackageInstaller.d.ts +233 -0
  33. package/dist/env/PackageInstaller.d.ts.map +1 -0
  34. package/dist/env/PackageInstaller.js +609 -0
  35. package/dist/env/PackageInstaller.js.map +1 -0
  36. package/dist/env/PythonDetector.d.ts +103 -0
  37. package/dist/env/PythonDetector.d.ts.map +1 -0
  38. package/dist/env/PythonDetector.js +381 -0
  39. package/dist/env/PythonDetector.js.map +1 -0
  40. package/dist/env/VenvManager.d.ts +117 -0
  41. package/dist/env/VenvManager.d.ts.map +1 -0
  42. package/dist/env/VenvManager.js +331 -0
  43. package/dist/env/VenvManager.js.map +1 -0
  44. package/dist/index.d.ts +169 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +393 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/plugins/Plugin.interface.d.ts +41 -0
  49. package/dist/plugins/Plugin.interface.d.ts.map +1 -0
  50. package/dist/plugins/Plugin.interface.js +12 -0
  51. package/dist/plugins/Plugin.interface.js.map +1 -0
  52. package/dist/plugins/PluginManager.d.ts +26 -0
  53. package/dist/plugins/PluginManager.d.ts.map +1 -0
  54. package/dist/plugins/PluginManager.js +174 -0
  55. package/dist/plugins/PluginManager.js.map +1 -0
  56. package/dist/plugins/builtin/NumpyPlugin.d.ts +17 -0
  57. package/dist/plugins/builtin/NumpyPlugin.d.ts.map +1 -0
  58. package/dist/plugins/builtin/NumpyPlugin.js +41 -0
  59. package/dist/plugins/builtin/NumpyPlugin.js.map +1 -0
  60. package/dist/plugins/builtin/PandasPlugin.d.ts +19 -0
  61. package/dist/plugins/builtin/PandasPlugin.d.ts.map +1 -0
  62. package/dist/plugins/builtin/PandasPlugin.js +57 -0
  63. package/dist/plugins/builtin/PandasPlugin.js.map +1 -0
  64. package/dist/plugins/builtin/TorchPlugin.d.ts +23 -0
  65. package/dist/plugins/builtin/TorchPlugin.d.ts.map +1 -0
  66. package/dist/plugins/builtin/TorchPlugin.js +50 -0
  67. package/dist/plugins/builtin/TorchPlugin.js.map +1 -0
  68. package/dist/plugins/index.d.ts +7 -0
  69. package/dist/plugins/index.d.ts.map +1 -0
  70. package/dist/plugins/index.js +12 -0
  71. package/dist/plugins/index.js.map +1 -0
  72. package/dist/serialization/DataFrameBridge.d.ts +141 -0
  73. package/dist/serialization/DataFrameBridge.d.ts.map +1 -0
  74. package/dist/serialization/DataFrameBridge.js +355 -0
  75. package/dist/serialization/DataFrameBridge.js.map +1 -0
  76. package/dist/serialization/MsgPackSerializer.d.ts +45 -0
  77. package/dist/serialization/MsgPackSerializer.d.ts.map +1 -0
  78. package/dist/serialization/MsgPackSerializer.js +242 -0
  79. package/dist/serialization/MsgPackSerializer.js.map +1 -0
  80. package/dist/serialization/NumpyBridge.d.ts +96 -0
  81. package/dist/serialization/NumpyBridge.d.ts.map +1 -0
  82. package/dist/serialization/NumpyBridge.js +323 -0
  83. package/dist/serialization/NumpyBridge.js.map +1 -0
  84. package/dist/serialization/Serializer.d.ts +78 -0
  85. package/dist/serialization/Serializer.d.ts.map +1 -0
  86. package/dist/serialization/Serializer.js +281 -0
  87. package/dist/serialization/Serializer.js.map +1 -0
  88. package/dist/types/PythonTypeMapper.d.ts +87 -0
  89. package/dist/types/PythonTypeMapper.d.ts.map +1 -0
  90. package/dist/types/PythonTypeMapper.js +449 -0
  91. package/dist/types/PythonTypeMapper.js.map +1 -0
  92. package/dist/types/StubCache.d.ts +109 -0
  93. package/dist/types/StubCache.d.ts.map +1 -0
  94. package/dist/types/StubCache.js +333 -0
  95. package/dist/types/StubCache.js.map +1 -0
  96. package/dist/types/TypeGenerator.d.ts +139 -0
  97. package/dist/types/TypeGenerator.d.ts.map +1 -0
  98. package/dist/types/TypeGenerator.js +372 -0
  99. package/dist/types/TypeGenerator.js.map +1 -0
  100. package/dist/types/addon.d.ts +114 -0
  101. package/dist/types/addon.d.ts.map +1 -0
  102. package/dist/types/addon.js +32 -0
  103. package/dist/types/addon.js.map +1 -0
  104. package/dist/types/config.d.ts +175 -0
  105. package/dist/types/config.d.ts.map +1 -0
  106. package/dist/types/config.js +35 -0
  107. package/dist/types/config.js.map +1 -0
  108. package/dist/types/index.d.ts +10 -0
  109. package/dist/types/index.d.ts.map +1 -0
  110. package/dist/types/index.js +12 -0
  111. package/dist/types/index.js.map +1 -0
  112. package/dist/types/python.d.ts +235 -0
  113. package/dist/types/python.d.ts.map +1 -0
  114. package/dist/types/python.js +7 -0
  115. package/dist/types/python.js.map +1 -0
  116. package/dist/utils/ErrorTranslator.d.ts +83 -0
  117. package/dist/utils/ErrorTranslator.d.ts.map +1 -0
  118. package/dist/utils/ErrorTranslator.js +210 -0
  119. package/dist/utils/ErrorTranslator.js.map +1 -0
  120. package/dist/utils/Logger.d.ts +27 -0
  121. package/dist/utils/Logger.d.ts.map +1 -0
  122. package/dist/utils/Logger.js +115 -0
  123. package/dist/utils/Logger.js.map +1 -0
  124. package/dist/utils/MemoryMonitor.d.ts +44 -0
  125. package/dist/utils/MemoryMonitor.d.ts.map +1 -0
  126. package/dist/utils/MemoryMonitor.js +143 -0
  127. package/dist/utils/MemoryMonitor.js.map +1 -0
  128. package/package.json +177 -0
  129. package/python/error_handler.py +433 -0
  130. package/python/nodepyx_runtime.py +575 -0
  131. package/python/serializer.py +379 -0
  132. package/python/type_inspector.py +288 -0
  133. package/scripts/build-native.js +68 -0
  134. package/scripts/download-prebuilds.js +99 -0
  135. package/scripts/generate-stubs.js +405 -0
  136. package/scripts/install.js +260 -0
  137. package/src/core/PyCallable.ts +137 -0
  138. package/src/core/PyContext.ts +296 -0
  139. package/src/core/PyIterator.ts +294 -0
  140. package/src/core/PyModule.ts +194 -0
  141. package/src/core/PyProxy.ts +605 -0
  142. package/src/core/PyRuntime.ts +504 -0
  143. package/src/env/CondaManager.ts +451 -0
  144. package/src/env/PackageInstaller.ts +738 -0
  145. package/src/env/PythonDetector.ts +414 -0
  146. package/src/env/VenvManager.ts +396 -0
  147. package/src/index.ts +425 -0
  148. package/src/native/gil_guard.cpp +26 -0
  149. package/src/native/gil_guard.h +175 -0
  150. package/src/native/nodepyx_addon.cpp +886 -0
  151. package/src/native/python_bridge.cpp +790 -0
  152. package/src/native/python_bridge.h +257 -0
  153. package/src/native/thread_pool.cpp +336 -0
  154. package/src/native/thread_pool.h +175 -0
  155. package/src/native/type_converter.cpp +901 -0
  156. package/src/native/type_converter.h +272 -0
  157. package/src/nextjs/PyProvider.tsx +123 -0
  158. package/src/nextjs/index.ts +21 -0
  159. package/src/nextjs/usePython.ts +106 -0
  160. package/src/nextjs/withnodepyx.ts +88 -0
  161. package/src/plugins/Plugin.interface.ts +51 -0
  162. package/src/plugins/PluginManager.ts +155 -0
  163. package/src/plugins/builtin/NumpyPlugin.ts +36 -0
  164. package/src/plugins/builtin/PandasPlugin.ts +49 -0
  165. package/src/plugins/builtin/TorchPlugin.ts +56 -0
  166. package/src/plugins/index.ts +7 -0
  167. package/src/serialization/DataFrameBridge.ts +398 -0
  168. package/src/serialization/MsgPackSerializer.ts +220 -0
  169. package/src/serialization/NumpyBridge.ts +332 -0
  170. package/src/serialization/Serializer.ts +320 -0
  171. package/src/types/PythonTypeMapper.ts +495 -0
  172. package/src/types/StubCache.ts +340 -0
  173. package/src/types/TypeGenerator.ts +491 -0
  174. package/src/types/addon.ts +170 -0
  175. package/src/types/config.ts +226 -0
  176. package/src/types/index.ts +55 -0
  177. package/src/types/python.ts +309 -0
  178. package/src/types/stubs/numpy.d.ts +441 -0
  179. package/src/types/stubs/pandas.d.ts +575 -0
  180. package/src/types/stubs/sklearn.d.ts +728 -0
  181. package/src/types/stubs/torch.d.ts +694 -0
  182. package/src/utils/ErrorTranslator.ts +220 -0
  183. package/src/utils/Logger.ts +119 -0
  184. package/src/utils/MemoryMonitor.ts +175 -0
@@ -0,0 +1,226 @@
1
+ /**
2
+ * nodepyx — Core Configuration Types
3
+ * Full configuration interface for nodepyx runtime initialization.
4
+ */
5
+
6
+ export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
7
+
8
+ export interface VirtualenvConfig {
9
+ /** Path to virtualenv directory (e.g. './.nodepyx/venv') */
10
+ path: string;
11
+ /** Python packages to install (e.g. ['pandas', 'numpy', 'scikit-learn']) */
12
+ packages: string[];
13
+ /** Automatically install missing packages at startup */
14
+ autoInstall: boolean;
15
+ /** pip index URL override */
16
+ pipIndexUrl?: string;
17
+ /** Additional pip install args */
18
+ pipArgs?: string[];
19
+ }
20
+
21
+ export interface CondaConfig {
22
+ /** Name of the conda environment */
23
+ envName: string;
24
+ /** Path to conda executable */
25
+ condaPath?: string;
26
+ /** Channels to search for packages */
27
+ channels?: string[];
28
+ /** Packages to ensure are installed */
29
+ packages?: string[];
30
+ }
31
+
32
+ export interface GILConfig {
33
+ /**
34
+ * How often to release the GIL during long Python operations (microseconds).
35
+ * Lower values improve Node.js responsiveness at cost of Python throughput.
36
+ * Default: 5000 (5ms)
37
+ */
38
+ releaseInterval?: number;
39
+ /**
40
+ * Maximum time to wait for GIL acquisition before timing out (milliseconds).
41
+ * Default: 10000 (10s)
42
+ */
43
+ acquireTimeout?: number;
44
+ }
45
+
46
+ export interface ThreadPoolConfig {
47
+ /** Number of worker threads for Python execution. Default: 4 */
48
+ size?: number;
49
+ /** Max queue depth before backpressure is applied. Default: 1000 */
50
+ maxQueueSize?: number;
51
+ /** Thread idle timeout before shrinking pool (ms). Default: 30000 */
52
+ idleTimeout?: number;
53
+ }
54
+
55
+ export interface MemoryConfig {
56
+ /** Maximum Python heap size (e.g. '2GB', '512MB'). Default: '2GB' */
57
+ limit?: string;
58
+ /** Trigger Python GC when heap exceeds this threshold. Default: '1GB' */
59
+ gcThreshold?: string;
60
+ /** Enable leak detection in debug builds. Default: false */
61
+ leakDetection?: boolean;
62
+ }
63
+
64
+ export interface ProfilingConfig {
65
+ /** Enable CPU profiling. Default: false */
66
+ enabled?: boolean;
67
+ /** Output file for profile data */
68
+ outputFile?: string;
69
+ /** Sampling interval (microseconds). Default: 1000 */
70
+ samplingInterval?: number;
71
+ }
72
+
73
+ export interface nodepyxConfig {
74
+ /**
75
+ * Path to Python executable or virtualenv root.
76
+ * If not specified, auto-detects system Python.
77
+ * Examples: '/usr/bin/python3', './.venv', '/opt/conda/envs/myenv'
78
+ */
79
+ pythonPath?: string;
80
+
81
+ /**
82
+ * Virtualenv configuration — creates and manages a dedicated virtualenv.
83
+ * Takes precedence over pythonPath if specified.
84
+ */
85
+ virtualenv?: VirtualenvConfig;
86
+
87
+ /**
88
+ * Conda environment configuration.
89
+ * Takes precedence over virtualenv and pythonPath if specified.
90
+ */
91
+ conda?: CondaConfig;
92
+
93
+ /**
94
+ * Thread pool configuration for Python execution.
95
+ */
96
+ threadPool?: ThreadPoolConfig;
97
+
98
+ /**
99
+ * Legacy shorthand for threadPool.size.
100
+ * @deprecated Use threadPool.size instead.
101
+ */
102
+ threadPoolSize?: number;
103
+
104
+ /**
105
+ * Memory configuration for Python heap.
106
+ */
107
+ memory?: MemoryConfig;
108
+
109
+ /**
110
+ * Legacy shorthand for memory.limit.
111
+ * @deprecated Use memory.limit instead.
112
+ */
113
+ memoryLimit?: string;
114
+
115
+ /**
116
+ * Directory for TypeScript type stubs generated from Python modules.
117
+ * Default: './.nodepyx/stubs'
118
+ */
119
+ stubsDir?: string;
120
+
121
+ /**
122
+ * Log level for nodepyx internal logging.
123
+ * Default: 'warn'
124
+ */
125
+ logLevel?: LogLevel;
126
+
127
+ /**
128
+ * Profiling configuration.
129
+ */
130
+ profiling?: ProfilingConfig;
131
+
132
+ /**
133
+ * Legacy shorthand for profiling.enabled.
134
+ * @deprecated Use profiling.enabled instead.
135
+ */
136
+ enableProfiling?: boolean;
137
+
138
+ /**
139
+ * Timeout for individual Python calls (milliseconds).
140
+ * Default: 30000 (30s)
141
+ */
142
+ callTimeout?: number;
143
+
144
+ /**
145
+ * GIL (Global Interpreter Lock) management configuration.
146
+ */
147
+ gil?: GILConfig;
148
+
149
+ /**
150
+ * Additional Python sys.path entries.
151
+ * Inserted at sys.path[0] in order.
152
+ */
153
+ pythonPath_extra?: string[];
154
+
155
+ /**
156
+ * Environment variables to set for the Python interpreter.
157
+ */
158
+ env?: Record<string, string>;
159
+
160
+ /**
161
+ * Enable experimental features. Use with caution.
162
+ */
163
+ experimental?: {
164
+ /** Use SharedArrayBuffer for NumPy transfers. Default: true */
165
+ sharedArrayBuffer?: boolean;
166
+ /** Cache Proxy chain resolutions. Default: true */
167
+ proxyCache?: boolean;
168
+ /** Lazy attribute resolution. Default: true */
169
+ lazyResolution?: boolean;
170
+ };
171
+ }
172
+
173
+ /**
174
+ * Resolved and normalized configuration (all fields filled with defaults).
175
+ */
176
+ export interface ResolvednodepyxConfig {
177
+ pythonExecutable: string;
178
+ pythonHome: string;
179
+ threadPoolSize: number;
180
+ maxQueueSize: number;
181
+ idleTimeout: number;
182
+ memoryLimit: string;
183
+ gcThreshold: string;
184
+ leakDetection: boolean;
185
+ stubsDir: string;
186
+ logLevel: LogLevel;
187
+ callTimeout: number;
188
+ gil: Required<GILConfig>;
189
+ profilingEnabled: boolean;
190
+ profilingFile?: string;
191
+ profilingSamplingInterval: number;
192
+ sharedArrayBuffer: boolean;
193
+ proxyCache: boolean;
194
+ lazyResolution: boolean;
195
+ env: Record<string, string>;
196
+ pythonPathExtra: string[];
197
+ }
198
+
199
+ export function resolveConfig(config: nodepyxConfig = {}): ResolvednodepyxConfig {
200
+ return {
201
+ pythonExecutable: config.pythonPath ?? 'python3',
202
+ pythonHome: config.pythonPath ?? '',
203
+ threadPoolSize: config.threadPool?.size ?? config.threadPoolSize ?? 4,
204
+ maxQueueSize: config.threadPool?.maxQueueSize ?? 1000,
205
+ idleTimeout: config.threadPool?.idleTimeout ?? 30000,
206
+ memoryLimit: config.memory?.limit ?? config.memoryLimit ?? '2GB',
207
+ gcThreshold: config.memory?.gcThreshold ?? '1GB',
208
+ leakDetection: config.memory?.leakDetection ?? false,
209
+ stubsDir: config.stubsDir ?? './.nodepyx/stubs',
210
+ logLevel: config.logLevel ?? 'warn',
211
+ callTimeout: config.callTimeout ?? 30000,
212
+ gil: {
213
+ releaseInterval: config.gil?.releaseInterval ?? 5000,
214
+ acquireTimeout: config.gil?.acquireTimeout ?? 10000,
215
+ },
216
+ profilingEnabled: config.profiling?.enabled ?? config.enableProfiling ?? false,
217
+ profilingFile: config.profiling?.outputFile,
218
+ profilingSamplingInterval: config.profiling?.samplingInterval ?? 1000,
219
+ sharedArrayBuffer: config.experimental?.sharedArrayBuffer ?? true,
220
+ proxyCache: config.experimental?.proxyCache ?? true,
221
+ lazyResolution: config.experimental?.lazyResolution ?? true,
222
+ env: config.env ?? {},
223
+ pythonPathExtra: config.pythonPath_extra ?? [],
224
+ };
225
+ }
226
+
@@ -0,0 +1,55 @@
1
+ /**
2
+ * nodepyx — Types Index
3
+ * Re-exports all public type definitions.
4
+ */
5
+
6
+ export type {
7
+ nodepyxConfig,
8
+ ResolvednodepyxConfig,
9
+ VirtualenvConfig,
10
+ CondaConfig,
11
+ GILConfig,
12
+ ThreadPoolConfig,
13
+ MemoryConfig,
14
+ ProfilingConfig,
15
+ LogLevel,
16
+ } from './config';
17
+
18
+ export { resolveConfig } from './config';
19
+
20
+ export type {
21
+ PyObjectId,
22
+ PyTypeName,
23
+ PyTypeInfo,
24
+ PyParamInfo,
25
+ PyMemberInfo,
26
+ PyCallableInfo,
27
+ PyClassInfo,
28
+ PyModuleInspection,
29
+ SerializedFormat,
30
+ SerializedValue,
31
+ SerializedMetadata,
32
+ PyCallResult,
33
+ PyErrorInfo,
34
+ PyIteratorState,
35
+ PyIteratorNext,
36
+ DataFrameResult,
37
+ SeriesResult,
38
+ NumPyArrayResult,
39
+ AttributePath,
40
+ PyProxyInterface,
41
+ } from './python';
42
+
43
+ export type {
44
+ NativeAddon,
45
+ AddonInitOptions,
46
+ AddonImportResult,
47
+ AddonAttributeResult,
48
+ AddonCallOptions,
49
+ AddonIteratorResult,
50
+ AddonMemoryStats,
51
+ AddonProfilingReport,
52
+ } from './addon';
53
+
54
+ export { loadNativeAddon } from './addon';
55
+
@@ -0,0 +1,309 @@
1
+ /**
2
+ * nodepyx — Python Object Type Definitions
3
+ * Core types for representing Python objects in TypeScript.
4
+ */
5
+
6
+ /**
7
+ * Unique identifier for a Python object in the CPython heap.
8
+ * Stored as a C-level pointer (opaque to JavaScript).
9
+ */
10
+ export type PyObjectId = number & { readonly __brand: 'PyObjectId' };
11
+
12
+ /**
13
+ * Python built-in type names.
14
+ */
15
+ export type PyTypeName =
16
+ | 'int'
17
+ | 'float'
18
+ | 'complex'
19
+ | 'bool'
20
+ | 'str'
21
+ | 'bytes'
22
+ | 'bytearray'
23
+ | 'list'
24
+ | 'tuple'
25
+ | 'dict'
26
+ | 'set'
27
+ | 'frozenset'
28
+ | 'NoneType'
29
+ | 'function'
30
+ | 'method'
31
+ | 'builtin_function_or_method'
32
+ | 'module'
33
+ | 'type'
34
+ | 'classmethod'
35
+ | 'staticmethod'
36
+ | 'property'
37
+ | 'generator'
38
+ | 'coroutine'
39
+ | 'async_generator'
40
+ | 'iterator'
41
+ | 'DataFrame'
42
+ | 'Series'
43
+ | 'ndarray'
44
+ | 'Tensor'
45
+ | string;
46
+
47
+ /**
48
+ * Metadata about a Python object's type.
49
+ */
50
+ export interface PyTypeInfo {
51
+ typeName: PyTypeName;
52
+ moduleName?: string;
53
+ qualName?: string;
54
+ isCallable: boolean;
55
+ isIterable: boolean;
56
+ isAsyncIterable: boolean;
57
+ isAwaitable: boolean;
58
+ isClass: boolean;
59
+ isModule: boolean;
60
+ isNone: boolean;
61
+ isPrimitive: boolean;
62
+ isNumeric: boolean;
63
+ isSequence: boolean;
64
+ isMapping: boolean;
65
+ }
66
+
67
+ /**
68
+ * Parameter info from Python function introspection.
69
+ */
70
+ export interface PyParamInfo {
71
+ name: string;
72
+ type: string;
73
+ optional: boolean;
74
+ hasDefault: boolean;
75
+ defaultValue?: unknown;
76
+ kind: 'positional_only' | 'positional_or_keyword' | 'var_positional' | 'keyword_only' | 'var_keyword';
77
+ }
78
+
79
+ /**
80
+ * Member/attribute info for a Python class or module.
81
+ */
82
+ export interface PyMemberInfo {
83
+ name: string;
84
+ type: string;
85
+ isReadOnly: boolean;
86
+ docstring?: string;
87
+ }
88
+
89
+ /**
90
+ * Full introspection result for a Python callable.
91
+ */
92
+ export interface PyCallableInfo {
93
+ name: string;
94
+ qualName: string;
95
+ docstring: string;
96
+ parameters: PyParamInfo[];
97
+ returnType: string;
98
+ isMethod: boolean;
99
+ isClassMethod: boolean;
100
+ isStaticMethod: boolean;
101
+ isCoroutine: boolean;
102
+ isGenerator: boolean;
103
+ }
104
+
105
+ /**
106
+ * Full introspection result for a Python class.
107
+ */
108
+ export interface PyClassInfo {
109
+ name: string;
110
+ qualName: string;
111
+ docstring: string;
112
+ bases: string[];
113
+ members: PyMemberInfo[];
114
+ methods: PyCallableInfo[];
115
+ properties: PyMemberInfo[];
116
+ classMethods: PyCallableInfo[];
117
+ staticMethods: PyCallableInfo[];
118
+ }
119
+
120
+ /**
121
+ * Full introspection result for a Python module.
122
+ */
123
+ export interface PyModuleInspection {
124
+ name: string;
125
+ file?: string;
126
+ docstring: string;
127
+ version?: string;
128
+ functions: PyCallableInfo[];
129
+ classes: PyClassInfo[];
130
+ constants: PyMemberInfo[];
131
+ submodules: string[];
132
+ }
133
+
134
+ /**
135
+ * Serialized wire format for Python ↔ JavaScript data transfer.
136
+ */
137
+ export type SerializedFormat =
138
+ | 'json'
139
+ | 'msgpack'
140
+ | 'numpy_array'
141
+ | 'dataframe'
142
+ | 'series'
143
+ | 'pandas_dataframe'
144
+ | 'pandas_series'
145
+ | 'torch_tensor'
146
+ | 'python_ref'
147
+ | 'bytes'
148
+ | 'none'
149
+ | number; // numeric codes from the C++ addon (0=json,1=msgpack,2=numpy,3=df,4=series,6=ref,7=bytes,8=none)
150
+
151
+ export interface SerializedValue {
152
+ format: SerializedFormat;
153
+ data: Uint8Array | string | null | undefined;
154
+ metadata?: SerializedMetadata;
155
+ }
156
+
157
+ export interface SerializedMetadata {
158
+ /** For python_ref: the object ID */
159
+ objectId?: number;
160
+ /** For numpy_array: dtype, shape, strides */
161
+ dtype?: string;
162
+ shape?: number[];
163
+ strides?: number[];
164
+ order?: 'C' | 'F';
165
+ /** For numpy_array: item size in bytes (snake_case variant) */
166
+ itemsize?: number;
167
+ /** For pandas objects: column names, dtypes, index */
168
+ columns?: string[];
169
+ columnDtypes?: string[];
170
+ index?: unknown[];
171
+ indexName?: string;
172
+ /** For pandas: orient (split/records/index/columns/values) */
173
+ orient?: string;
174
+ /** For Series: series name */
175
+ name?: string;
176
+ /** For torch tensors */
177
+ device?: string;
178
+ requiresGrad?: boolean;
179
+ /** General */
180
+ length?: number;
181
+ size?: number;
182
+ itemSize?: number;
183
+ }
184
+
185
+ /**
186
+ * Result from a Python function call.
187
+ */
188
+ export interface PyCallResult {
189
+ success: boolean;
190
+ value?: SerializedValue;
191
+ error?: PyErrorInfo;
192
+ objectId?: PyObjectId;
193
+ isObject?: boolean;
194
+ }
195
+
196
+ /**
197
+ * Python exception information.
198
+ */
199
+ export interface PyErrorInfo {
200
+ /** Python exception class name, e.g. 'ValueError', 'FileNotFoundError' */
201
+ type: string;
202
+ /** Exception message */
203
+ message: string;
204
+ /** Full Python traceback */
205
+ traceback: string;
206
+ /** Exception module, e.g. 'builtins', 'pandas.errors' */
207
+ module?: string;
208
+ /** Chained exception */
209
+ cause?: PyErrorInfo;
210
+ }
211
+
212
+ /**
213
+ * Iterator state for Python iterators.
214
+ */
215
+ export interface PyIteratorState {
216
+ iteratorId: number;
217
+ objectId: PyObjectId;
218
+ done: boolean;
219
+ position: number;
220
+ }
221
+
222
+ /**
223
+ * Result from iterator next() call.
224
+ */
225
+ export interface PyIteratorNext {
226
+ done: boolean;
227
+ value?: SerializedValue;
228
+ error?: PyErrorInfo;
229
+ }
230
+
231
+ /**
232
+ * DataFrame representation after deserialization.
233
+ */
234
+ export interface DataFrameResult {
235
+ columns: string[];
236
+ /** Row data as array of column-keyed objects */
237
+ data: Record<string, unknown>[];
238
+ /** Alias for data — array of records (row objects) */
239
+ records: Record<string, unknown>[];
240
+ index: unknown[];
241
+ dtypes: Record<string, string>;
242
+ shape: [number, number];
243
+ }
244
+
245
+ /**
246
+ * Series representation after deserialization.
247
+ */
248
+ export interface SeriesResult {
249
+ name: string;
250
+ /** Series values */
251
+ data: unknown[];
252
+ /** Alias for data */
253
+ values: unknown[];
254
+ index: unknown[];
255
+ dtype: string;
256
+ length: number;
257
+ }
258
+
259
+ /**
260
+ * A typed array backed by numpy data.
261
+ */
262
+ export type NumpyTypedArray =
263
+ | Float32Array
264
+ | Float64Array
265
+ | Int8Array
266
+ | Int16Array
267
+ | Int32Array
268
+ | BigInt64Array
269
+ | Uint8Array
270
+ | Uint16Array
271
+ | Uint32Array
272
+ | BigUint64Array;
273
+
274
+ /**
275
+ * NumPy array representation after deserialization.
276
+ * Contains the typed array data plus metadata (dtype, shape, ndim).
277
+ */
278
+ export interface NumPyArrayResult {
279
+ /** The underlying typed array */
280
+ data: NumpyTypedArray;
281
+ /** NumPy dtype string, e.g. 'float64' */
282
+ dtype: string;
283
+ /** Array shape */
284
+ shape: number[];
285
+ /** Number of dimensions */
286
+ ndim: number;
287
+ }
288
+
289
+ /**
290
+ * Attribute resolution path for lazy Proxy chains.
291
+ */
292
+ export type AttributePath = string[];
293
+
294
+ /**
295
+ * The core PyProxy interface — wraps any Python object.
296
+ * All properties return new PyProxy instances (lazy).
297
+ * Calling the proxy or awaiting it triggers the Python call.
298
+ */
299
+ export interface PyProxyInterface {
300
+ readonly _pyObjectId: PyObjectId;
301
+ readonly _path: AttributePath;
302
+ readonly _isResolved: boolean;
303
+ then(
304
+ onfulfilled?: (value: unknown) => unknown,
305
+ onrejected?: (reason: PyErrorInfo) => unknown
306
+ ): Promise<unknown>;
307
+ [key: string]: unknown;
308
+ }
309
+