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,55 @@
1
+ /**
2
+ * nodepyx — PyModule
3
+ * Represents a Python module with its full namespace.
4
+ * Inherits from PyProxy but adds module-specific introspection.
5
+ */
6
+ import { PyProxy } from './PyProxy';
7
+ import type { NativeAddon } from '../types/addon';
8
+ import type { PyObjectId, PyModuleInspection } from '../types/python';
9
+ /**
10
+ * PyModule extends PyProxy with module-specific utilities.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const pd = await py.import('pandas');
15
+ * // pd is a PyModule
16
+ * const df = await pd.read_csv('data.csv'); // access module attribute
17
+ * const info = await pd.__nodepyx_inspect__(); // get module metadata
18
+ * ```
19
+ */
20
+ export declare class PyModule extends PyProxy {
21
+ private readonly _moduleName;
22
+ private _inspection;
23
+ constructor(objectId: PyObjectId, moduleName: string, addon: NativeAddon, callTimeout?: number);
24
+ /** The Python module name */
25
+ get moduleName(): string;
26
+ /** Object ID in Python heap */
27
+ get objectId(): PyObjectId;
28
+ /**
29
+ * Inspect the module — returns detailed type information.
30
+ * Cached after first call.
31
+ */
32
+ inspect(): Promise<PyModuleInspection>;
33
+ /**
34
+ * Get list of public names in the module (dir() equivalent).
35
+ */
36
+ getNames(): Promise<string[]>;
37
+ /**
38
+ * Check if the module has a specific attribute.
39
+ */
40
+ has(name: string): Promise<boolean>;
41
+ /**
42
+ * Get module version string.
43
+ */
44
+ getVersion(): Promise<string | null>;
45
+ /**
46
+ * Reload the module (re-imports from Python).
47
+ */
48
+ reload(): Promise<void>;
49
+ /**
50
+ * Create a PyModule from an existing addon import result.
51
+ */
52
+ static fromRef(objectId: PyObjectId, moduleName: string, addon: NativeAddon, callTimeout?: number): PyModule;
53
+ toString(): string;
54
+ }
55
+ //# sourceMappingURL=PyModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PyModule.d.ts","sourceRoot":"","sources":["../../src/core/PyModule.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKtE;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,SAAQ,OAAO;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,WAAW,CAAmC;gBAGpD,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,WAAW,EAClB,WAAW,CAAC,EAAE,MAAM;IAatB,6BAA6B;IAC7B,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,+BAA+B;IAC/B,IAAI,QAAQ,IAAI,UAAU,CAEzB;IAED;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,kBAAkB,CAAC;IA0E5C;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAcnC;;OAEG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAK1C;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ7B;;OAEG;IACH,MAAM,CAAC,OAAO,CACZ,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,WAAW,EAClB,WAAW,CAAC,EAAE,MAAM,GACnB,QAAQ;IAIF,QAAQ,IAAI,MAAM;CAG5B"}
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /**
3
+ * nodepyx — PyModule
4
+ * Represents a Python module with its full namespace.
5
+ * Inherits from PyProxy but adds module-specific introspection.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.PyModule = void 0;
9
+ const PyProxy_1 = require("./PyProxy");
10
+ const Logger_1 = require("../utils/Logger");
11
+ const logger = new Logger_1.Logger('PyModule');
12
+ /**
13
+ * PyModule extends PyProxy with module-specific utilities.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const pd = await py.import('pandas');
18
+ * // pd is a PyModule
19
+ * const df = await pd.read_csv('data.csv'); // access module attribute
20
+ * const info = await pd.__nodepyx_inspect__(); // get module metadata
21
+ * ```
22
+ */
23
+ class PyModule extends PyProxy_1.PyProxy {
24
+ _moduleName;
25
+ _inspection = null;
26
+ constructor(objectId, moduleName, addon, callTimeout) {
27
+ super({
28
+ objectId,
29
+ path: [],
30
+ addon,
31
+ isResolved: false,
32
+ callTimeout,
33
+ childCache: new Map(),
34
+ });
35
+ this._moduleName = moduleName;
36
+ }
37
+ /** The Python module name */
38
+ get moduleName() {
39
+ return this._moduleName;
40
+ }
41
+ /** Object ID in Python heap */
42
+ get objectId() {
43
+ return this[PyProxy_1.PYPROXY_INTERNAL].objectId;
44
+ }
45
+ /**
46
+ * Inspect the module — returns detailed type information.
47
+ * Cached after first call.
48
+ */
49
+ async inspect() {
50
+ if (this._inspection) {
51
+ return this._inspection;
52
+ }
53
+ const addon = this[PyProxy_1.PYPROXY_INTERNAL].addon;
54
+ try {
55
+ // Run Python introspection
56
+ const result = await addon.runPythonCode(`
57
+ import json
58
+ import sys
59
+
60
+ def _inspect_module_${this._moduleName.replace(/\./g, '_')}():
61
+ try:
62
+ import ${this._moduleName} as _mod
63
+ import inspect
64
+
65
+ result = {
66
+ 'name': '${this._moduleName}',
67
+ 'file': getattr(_mod, '__file__', None),
68
+ 'docstring': (getattr(_mod, '__doc__', '') or '')[:500],
69
+ 'version': getattr(_mod, '__version__', None),
70
+ 'functions': [],
71
+ 'classes': [],
72
+ 'constants': [],
73
+ 'submodules': [],
74
+ }
75
+
76
+ for name in dir(_mod):
77
+ if name.startswith('_'):
78
+ continue
79
+ try:
80
+ obj = getattr(_mod, name)
81
+ if inspect.ismodule(obj):
82
+ result['submodules'].append(name)
83
+ elif inspect.isclass(obj):
84
+ result['classes'].append({'name': name, 'type': 'class'})
85
+ elif callable(obj):
86
+ result['functions'].append({'name': name, 'type': 'function'})
87
+ else:
88
+ result['constants'].append({'name': name, 'type': type(obj).__name__})
89
+ except Exception:
90
+ pass
91
+
92
+ return result
93
+ except Exception as e:
94
+ return {'name': '${this._moduleName}', 'error': str(e), 'functions': [], 'classes': [], 'constants': [], 'submodules': []}
95
+
96
+ _result = _inspect_module_${this._moduleName.replace(/\./g, '_')}()
97
+ json.dumps(_result)
98
+ `);
99
+ const r = result;
100
+ if (r.success && r.resultJson) {
101
+ const parsed = JSON.parse(r.resultJson.replace(/^"|"$/g, '').replace(/\\"/g, '"'));
102
+ this._inspection = parsed;
103
+ return this._inspection;
104
+ }
105
+ }
106
+ catch (err) {
107
+ logger.warn(`Failed to inspect module ${this._moduleName}`, err);
108
+ }
109
+ // Return minimal inspection
110
+ this._inspection = {
111
+ name: this._moduleName,
112
+ docstring: '',
113
+ functions: [],
114
+ classes: [],
115
+ constants: [],
116
+ submodules: [],
117
+ };
118
+ return this._inspection;
119
+ }
120
+ /**
121
+ * Get list of public names in the module (dir() equivalent).
122
+ */
123
+ async getNames() {
124
+ const addon = this[PyProxy_1.PYPROXY_INTERNAL].addon;
125
+ const result = await addon.getObjectKeys(this.objectId);
126
+ const r = result;
127
+ if (r.success && r.resultJson) {
128
+ try {
129
+ return JSON.parse(r.resultJson);
130
+ }
131
+ catch {
132
+ return [];
133
+ }
134
+ }
135
+ return [];
136
+ }
137
+ /**
138
+ * Check if the module has a specific attribute.
139
+ */
140
+ async has(name) {
141
+ const addon = this[PyProxy_1.PYPROXY_INTERNAL].addon;
142
+ return addon.hasAttribute(this.objectId, name);
143
+ }
144
+ /**
145
+ * Get module version string.
146
+ */
147
+ async getVersion() {
148
+ const inspection = await this.inspect();
149
+ return inspection.version ?? null;
150
+ }
151
+ /**
152
+ * Reload the module (re-imports from Python).
153
+ */
154
+ async reload() {
155
+ const addon = this[PyProxy_1.PYPROXY_INTERNAL].addon;
156
+ await addon.reloadModule(this.objectId);
157
+ this._inspection = null; // Clear inspection cache
158
+ this[PyProxy_1.PYPROXY_INTERNAL].childCache.clear(); // Clear attribute cache
159
+ logger.debug(`Module ${this._moduleName} reloaded`);
160
+ }
161
+ /**
162
+ * Create a PyModule from an existing addon import result.
163
+ */
164
+ static fromRef(objectId, moduleName, addon, callTimeout) {
165
+ return new PyModule(objectId, moduleName, addon, callTimeout);
166
+ }
167
+ toString() {
168
+ return `[PyModule '${this._moduleName}' id=${this.objectId}]`;
169
+ }
170
+ }
171
+ exports.PyModule = PyModule;
172
+ //# sourceMappingURL=PyModule.js.map
@@ -0,0 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odepyx's JavaScript API.
5
+ * Every Python object is represented as a PyProxy — a JavaScript Proxy that:
6
+ *
7
+ * 1. Intercepts property access → creates lazy child PyProxy
8
+ * 2. Intercepts function call → sends to Python worker thread
9
+ * 3. Intercepts `then` → resolves the proxy chain into a value (makes it awaitable)
10
+ * 4. Intercepts Symbol.iterator → enables for...of loops
11
+ * 5. Intercepts Symbol.asyncIterator → enables for await...of loops
12
+ * 6. Intercepts property assignment → sets Python attribute
13
+ *
14
+ * The key insight: attributes are NOT resolved eagerly. The chain
15
+ * `df.groupby('country').agg({'sales': 'sum'}).reset_index()`
16
+ * creates a chain of PyProxy objects, each recording the operation,
17
+ * and only executes when you `await` the final result.
18
+ */
19
+ import type { NativeAddon } from '../types/addon';
20
+ import type { PyObjectId, AttributePath, SerializedValue } from '../types/python';
21
+ export declare const PYPROXY_INTERNAL: unique symbol;
22
+ export declare const PYPROXY_OBJECTID: unique symbol;
23
+ export declare const PYPROXY_PATH: unique symbol;
24
+ /**
25
+ * Internal state of a PyProxy.
26
+ */
27
+ export interface PyProxyInternal {
28
+ objectId: PyObjectId;
29
+ path: AttributePath;
30
+ addon: NativeAddon;
31
+ isResolved: boolean;
32
+ callTimeout?: number;
33
+ /** Cache of child proxies keyed by attribute name */
34
+ childCache: Map<string, PyProxy>;
35
+ }
36
+ /**
37
+ * PyProxy — wraps any Python object in JavaScript.
38
+ *
39
+ * Usage:
40
+ * ```typescript
41
+ * const pd = await py.import('pandas');
42
+ * const df = await pd.read_csv('data.csv'); // df is a PyProxy
43
+ * const rows = await df.describe().to_dict('records'); // chained calls
44
+ * ```
45
+ */
46
+ export declare class PyProxy {
47
+ /** Internal state — do not access directly from outside */
48
+ readonly [PYPROXY_INTERNAL]: PyProxyInternal;
49
+ constructor(internal: PyProxyInternal);
50
+ static readonly handler: ProxyHandler<PyProxy>;
51
+ private _resolve;
52
+ private _call;
53
+ private _makeAsyncIterator;
54
+ private _setAttr;
55
+ static _createFromObjectId(objectId: PyObjectId, path: AttributePath, addon: NativeAddon, callTimeout?: number): PyProxy;
56
+ static _deserializeAddonResult(result: unknown, internal: PyProxyInternal): unknown;
57
+ static _serializeArg(value: unknown): Promise<SerializedValue>;
58
+ static _getTypedArrayDtype(arr: ArrayBufferView): string;
59
+ static _isPlainObject(obj: unknown): boolean;
60
+ }
61
+ /**
62
+ * Check if a value is a PyProxy.
63
+ */
64
+ export declare function isPyProxy(value: unknown): value is PyProxy;
65
+ //# sourceMappingURL=PyProxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PyProxy.d.ts","sourceRoot":"","sources":["../../src/core/PyProxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAOzB,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAC3D,eAAO,MAAM,gBAAgB,eAA6B,CAAC;AAC3D,eAAO,MAAM,YAAY,eAAyB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,UAAU,CAAC;IACrB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,qBAAa,OAAO;IAClB,6DAA6D;IAC7D,QAAQ,CAAC,CAAC,gBAAgB,CAAC,EAAE,eAAe,CAAC;gBAEjC,QAAQ,EAAE,eAAe;IAOrC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CA6J5C;YAIY,QAAQ;YA8BR,KAAK;YA4DJ,kBAAkB;YAyEnB,QAAQ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