concurrent-c-node 0.15.0__tar.gz → 0.17.0__tar.gz
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.
- concurrent_c_node-0.17.0/PKG-INFO +182 -0
- concurrent_c_node-0.17.0/README.md +171 -0
- concurrent_c_node-0.17.0/concurrent_c_node.egg-info/PKG-INFO +182 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/pyproject.toml +1 -1
- concurrent_c_node-0.15.0/PKG-INFO +0 -263
- concurrent_c_node-0.15.0/README.md +0 -252
- concurrent_c_node-0.15.0/concurrent_c_node.egg-info/PKG-INFO +0 -263
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/__init__.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/benchmarks/__init__.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/benchmarks/multi_domain.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/broker.cjs +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/examples/__init__.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/examples/bench_wire.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/cc_node/examples/use_node.py +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/concurrent_c_node.egg-info/SOURCES.txt +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/concurrent_c_node.egg-info/dependency_links.txt +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/concurrent_c_node.egg-info/top_level.txt +0 -0
- {concurrent_c_node-0.15.0 → concurrent_c_node-0.17.0}/setup.cfg +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: concurrent-c-node
|
|
3
|
+
Version: 0.17.0
|
|
4
|
+
Summary: JavaScript and npm packages from Python over the Concurrent-C bridge: one spawned Node child per domain, host-controlled lifetime.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/sreekotay/concurrent-c
|
|
7
|
+
Project-URL: Documentation, https://github.com/sreekotay/concurrent-c/blob/main/pypi/cc-node/README.md
|
|
8
|
+
Keywords: javascript,node,npm,interop,concurrent-c
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# concurrent-c-node
|
|
13
|
+
|
|
14
|
+
Call Node (and npm packages) from Python.
|
|
15
|
+
Native types, exceptions, callbacks, and async all cross the boundary.
|
|
16
|
+
|
|
17
|
+
Part of [Concurrent-C](https://github.com/sreekotay/concurrent-c) — a
|
|
18
|
+
strict C11-superset preprocessor: `.ccs` lowers to plain C and compiles
|
|
19
|
+
with your host C compiler. (This bridge itself is pure Python stdlib —
|
|
20
|
+
no native build.)
|
|
21
|
+
|
|
22
|
+
Map of the three boundaries (CC hosts JS, native modules, this package
|
|
23
|
+
bridge):
|
|
24
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import cc_node
|
|
28
|
+
|
|
29
|
+
js = cc_node.create() # always a child `node` process
|
|
30
|
+
_ = js.require('lodash') # cwd node_modules
|
|
31
|
+
_.chunk([1, 2, 3, 4, 5], 2) # [[1, 2], [3, 4], [5]]
|
|
32
|
+
|
|
33
|
+
semver = js.require('semver')
|
|
34
|
+
semver.satisfies('1.2.3', '^1.0.0') # True
|
|
35
|
+
|
|
36
|
+
js.destroy() # or: with cc_node.create() as js:
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Unlike [`concurrent-c-python`](https://github.com/sreekotay/concurrent-c/tree/main/npm/cc-python)
|
|
40
|
+
(in-process by default), every `create()` here is a separate Node —
|
|
41
|
+
real addons, crash isolation, measurable wire. N domains = N processes.
|
|
42
|
+
|
|
43
|
+
| | this package | CC hosted (`cc_js_new(false, …)`) |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| API | `cc_node.create()` | `.ccs` program |
|
|
46
|
+
| Where | child `node` | libnode in-process |
|
|
47
|
+
| Hot call | ~105µs RTT | sub-µs (needs libnode) |
|
|
48
|
+
| Bulk | shm (~9.5ms / 8MB) | in-process |
|
|
49
|
+
| Parallelism | N children | one process |
|
|
50
|
+
| Crash | child dies; parent lives | shared fate |
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
pip install concurrent-c-node # needs node on PATH
|
|
54
|
+
python -m cc_node.examples.use_node
|
|
55
|
+
python -m cc_node.examples.bench_wire
|
|
56
|
+
python -m cc_node.benchmarks.multi_domain
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Measured
|
|
60
|
+
|
|
61
|
+
[`bench_wire`](https://github.com/sreekotay/concurrent-c/blob/main/pypi/cc-node/cc_node/examples/bench_wire.py)
|
|
62
|
+
·
|
|
63
|
+
[`cc_node_bridge_py_20260810.txt`](https://github.com/sreekotay/concurrent-c/blob/main/perf/baselines/cc_node_bridge_py_20260810.txt):
|
|
64
|
+
|
|
65
|
+
| what | result |
|
|
66
|
+
|---|---|
|
|
67
|
+
| spawn (first eval) | 28ms |
|
|
68
|
+
| wire RTT | 105µs |
|
|
69
|
+
| Python callback round trip | 153µs |
|
|
70
|
+
| 8MB `array('d')` via shm | 9.5ms |
|
|
71
|
+
| same 8MB as JSON list | 499ms (~52×) |
|
|
72
|
+
|
|
73
|
+
Wire: line-JSON on dedicated fds (stdio stays yours). Bulk spill: private
|
|
74
|
+
0700 dir, 0600 files, removed with the bridge.
|
|
75
|
+
|
|
76
|
+
## Surface
|
|
77
|
+
|
|
78
|
+
- Plain data (numbers, str, bool, `None`, lists, non-empty dicts) by
|
|
79
|
+
value; else a domain-owned handle (attrs, calls, `str()` →
|
|
80
|
+
`String()`). Non-finite floats are tagged.
|
|
81
|
+
- Handles are per-domain. `stats()` / `release()` / idempotent
|
|
82
|
+
`destroy()`; afterwards: `bridge is closed`.
|
|
83
|
+
- Crash isolation, not a sandbox. `destroy()` is cooperative; an
|
|
84
|
+
in-flight CPU-bound call finishes or you kill the child
|
|
85
|
+
([`bridge_stress.md`](https://github.com/sreekotay/concurrent-c/blob/main/stress/bridge/bridge_stress.md)).
|
|
86
|
+
|
|
87
|
+
### Promises
|
|
88
|
+
|
|
89
|
+
Awaited in the child before the reply — no `async`/`await` on the
|
|
90
|
+
Python side (opposite of `concurrent-c-python` isolated):
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
fetchish = js.eval('async (x) => { return { doubled: x * 2 } }')
|
|
94
|
+
fetchish(21) # {'doubled': 42}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Callbacks
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
mapped = js.eval('(f) => [1, 2, 3].map(f)')(lambda x, *rest: x * 10)
|
|
101
|
+
# map passes (value, index, array) — take *rest
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Exceptions cross both ways with messages intact.
|
|
105
|
+
|
|
106
|
+
### Buffers
|
|
107
|
+
|
|
108
|
+
`bytes` / `array.array` / 1-D numpy → typed arrays (and back). Small
|
|
109
|
+
inline; large via shm.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import array
|
|
113
|
+
total = js.eval('(a) => a.reduce((s, x) => s + x, 0)')
|
|
114
|
+
total(array.array('d', range(1_000_000)))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Common issues
|
|
118
|
+
|
|
119
|
+
**`Cannot find module`.** `require` / `import` resolve from the Python
|
|
120
|
+
process cwd (`node_modules` next to your program), not from this wheel’s
|
|
121
|
+
site-packages. `npm install lodash` in the project directory is the fix;
|
|
122
|
+
or `create(node=…)` / `CC_NODE_BIN` when the wrong Node is on `PATH`.
|
|
123
|
+
|
|
124
|
+
### Empty `{}` stays a handle
|
|
125
|
+
|
|
126
|
+
An empty object has to stay on the Node side — a materialized Python
|
|
127
|
+
`dict` would lose later property use that matches Node. So
|
|
128
|
+
`js.eval('({})')` returns a live handle:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
o = js.eval('({})') # JsHandle, not {}
|
|
132
|
+
js.eval('(o) => { o.x = 1; return o.x }')(o) # 1
|
|
133
|
+
js.eval('({a: 1})') # {'a': 1} — data return
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Non-empty plain objects still cross as Python `dict`s. Same-domain
|
|
137
|
+
handles chain (`h.update(…).digest(…)`).
|
|
138
|
+
|
|
139
|
+
**Wire cost vs tiny work.** Round trip is ~100µs; a one-line JS helper
|
|
140
|
+
on three numbers loses to pure Python. Prefer Python (or a native CC
|
|
141
|
+
module) for small/hot work; use the bridge when Node/npm owns the kernel.
|
|
142
|
+
Multi-core: `python -m cc_node.benchmarks.multi_domain` (~2.8× on 3
|
|
143
|
+
domains here).
|
|
144
|
+
|
|
145
|
+
## Choosing node
|
|
146
|
+
|
|
147
|
+
1. `create(node='/path/to/node')`
|
|
148
|
+
2. `CC_NODE_BIN`
|
|
149
|
+
3. `node` on `PATH`
|
|
150
|
+
|
|
151
|
+
Packages: cwd `node_modules`, same as Node itself.
|
|
152
|
+
|
|
153
|
+
From Concurrent-C (not Python): `cc_js_new(false, &a)` hosted
|
|
154
|
+
(libnode), or `cc_js_new(true, &a)` for this wire —
|
|
155
|
+
[`jsdemo.shcc`](https://github.com/sreekotay/concurrent-c/blob/main/examples/js/jsdemo.shcc).
|
|
156
|
+
|
|
157
|
+
## Publishing
|
|
158
|
+
|
|
159
|
+
**PyPI Trusted Publishing (OIDC)** — no API token:
|
|
160
|
+
|
|
161
|
+
1. [Publishing settings](https://pypi.org/manage/project/concurrent-c-node/settings/publishing/):
|
|
162
|
+
owner `sreekotay`, repo `concurrent-c`, workflow `publish-cc-node.yml`,
|
|
163
|
+
environment `pypi`
|
|
164
|
+
2. GitHub Environment `pypi`
|
|
165
|
+
3. Bump `pyproject.toml`, push, then:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
gh workflow run publish-cc-node.yml
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Local / npm sibling:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
./scripts/publish_bridges.sh --publish --minor
|
|
175
|
+
gh workflow run publish-cc-node.yml
|
|
176
|
+
# twine fallback: … --pypi-twine
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Examples: `use_node`, `bench_wire`, `benchmarks.multi_domain`.
|
|
180
|
+
Stress: [`stress/bridge/`](https://github.com/sreekotay/concurrent-c/tree/main/stress/bridge).
|
|
181
|
+
Own hot path in C/CC → native module (40–90ns) —
|
|
182
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# concurrent-c-node
|
|
2
|
+
|
|
3
|
+
Call Node (and npm packages) from Python.
|
|
4
|
+
Native types, exceptions, callbacks, and async all cross the boundary.
|
|
5
|
+
|
|
6
|
+
Part of [Concurrent-C](https://github.com/sreekotay/concurrent-c) — a
|
|
7
|
+
strict C11-superset preprocessor: `.ccs` lowers to plain C and compiles
|
|
8
|
+
with your host C compiler. (This bridge itself is pure Python stdlib —
|
|
9
|
+
no native build.)
|
|
10
|
+
|
|
11
|
+
Map of the three boundaries (CC hosts JS, native modules, this package
|
|
12
|
+
bridge):
|
|
13
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import cc_node
|
|
17
|
+
|
|
18
|
+
js = cc_node.create() # always a child `node` process
|
|
19
|
+
_ = js.require('lodash') # cwd node_modules
|
|
20
|
+
_.chunk([1, 2, 3, 4, 5], 2) # [[1, 2], [3, 4], [5]]
|
|
21
|
+
|
|
22
|
+
semver = js.require('semver')
|
|
23
|
+
semver.satisfies('1.2.3', '^1.0.0') # True
|
|
24
|
+
|
|
25
|
+
js.destroy() # or: with cc_node.create() as js:
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Unlike [`concurrent-c-python`](https://github.com/sreekotay/concurrent-c/tree/main/npm/cc-python)
|
|
29
|
+
(in-process by default), every `create()` here is a separate Node —
|
|
30
|
+
real addons, crash isolation, measurable wire. N domains = N processes.
|
|
31
|
+
|
|
32
|
+
| | this package | CC hosted (`cc_js_new(false, …)`) |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| API | `cc_node.create()` | `.ccs` program |
|
|
35
|
+
| Where | child `node` | libnode in-process |
|
|
36
|
+
| Hot call | ~105µs RTT | sub-µs (needs libnode) |
|
|
37
|
+
| Bulk | shm (~9.5ms / 8MB) | in-process |
|
|
38
|
+
| Parallelism | N children | one process |
|
|
39
|
+
| Crash | child dies; parent lives | shared fate |
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
pip install concurrent-c-node # needs node on PATH
|
|
43
|
+
python -m cc_node.examples.use_node
|
|
44
|
+
python -m cc_node.examples.bench_wire
|
|
45
|
+
python -m cc_node.benchmarks.multi_domain
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Measured
|
|
49
|
+
|
|
50
|
+
[`bench_wire`](https://github.com/sreekotay/concurrent-c/blob/main/pypi/cc-node/cc_node/examples/bench_wire.py)
|
|
51
|
+
·
|
|
52
|
+
[`cc_node_bridge_py_20260810.txt`](https://github.com/sreekotay/concurrent-c/blob/main/perf/baselines/cc_node_bridge_py_20260810.txt):
|
|
53
|
+
|
|
54
|
+
| what | result |
|
|
55
|
+
|---|---|
|
|
56
|
+
| spawn (first eval) | 28ms |
|
|
57
|
+
| wire RTT | 105µs |
|
|
58
|
+
| Python callback round trip | 153µs |
|
|
59
|
+
| 8MB `array('d')` via shm | 9.5ms |
|
|
60
|
+
| same 8MB as JSON list | 499ms (~52×) |
|
|
61
|
+
|
|
62
|
+
Wire: line-JSON on dedicated fds (stdio stays yours). Bulk spill: private
|
|
63
|
+
0700 dir, 0600 files, removed with the bridge.
|
|
64
|
+
|
|
65
|
+
## Surface
|
|
66
|
+
|
|
67
|
+
- Plain data (numbers, str, bool, `None`, lists, non-empty dicts) by
|
|
68
|
+
value; else a domain-owned handle (attrs, calls, `str()` →
|
|
69
|
+
`String()`). Non-finite floats are tagged.
|
|
70
|
+
- Handles are per-domain. `stats()` / `release()` / idempotent
|
|
71
|
+
`destroy()`; afterwards: `bridge is closed`.
|
|
72
|
+
- Crash isolation, not a sandbox. `destroy()` is cooperative; an
|
|
73
|
+
in-flight CPU-bound call finishes or you kill the child
|
|
74
|
+
([`bridge_stress.md`](https://github.com/sreekotay/concurrent-c/blob/main/stress/bridge/bridge_stress.md)).
|
|
75
|
+
|
|
76
|
+
### Promises
|
|
77
|
+
|
|
78
|
+
Awaited in the child before the reply — no `async`/`await` on the
|
|
79
|
+
Python side (opposite of `concurrent-c-python` isolated):
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
fetchish = js.eval('async (x) => { return { doubled: x * 2 } }')
|
|
83
|
+
fetchish(21) # {'doubled': 42}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Callbacks
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
mapped = js.eval('(f) => [1, 2, 3].map(f)')(lambda x, *rest: x * 10)
|
|
90
|
+
# map passes (value, index, array) — take *rest
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Exceptions cross both ways with messages intact.
|
|
94
|
+
|
|
95
|
+
### Buffers
|
|
96
|
+
|
|
97
|
+
`bytes` / `array.array` / 1-D numpy → typed arrays (and back). Small
|
|
98
|
+
inline; large via shm.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import array
|
|
102
|
+
total = js.eval('(a) => a.reduce((s, x) => s + x, 0)')
|
|
103
|
+
total(array.array('d', range(1_000_000)))
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Common issues
|
|
107
|
+
|
|
108
|
+
**`Cannot find module`.** `require` / `import` resolve from the Python
|
|
109
|
+
process cwd (`node_modules` next to your program), not from this wheel’s
|
|
110
|
+
site-packages. `npm install lodash` in the project directory is the fix;
|
|
111
|
+
or `create(node=…)` / `CC_NODE_BIN` when the wrong Node is on `PATH`.
|
|
112
|
+
|
|
113
|
+
### Empty `{}` stays a handle
|
|
114
|
+
|
|
115
|
+
An empty object has to stay on the Node side — a materialized Python
|
|
116
|
+
`dict` would lose later property use that matches Node. So
|
|
117
|
+
`js.eval('({})')` returns a live handle:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
o = js.eval('({})') # JsHandle, not {}
|
|
121
|
+
js.eval('(o) => { o.x = 1; return o.x }')(o) # 1
|
|
122
|
+
js.eval('({a: 1})') # {'a': 1} — data return
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Non-empty plain objects still cross as Python `dict`s. Same-domain
|
|
126
|
+
handles chain (`h.update(…).digest(…)`).
|
|
127
|
+
|
|
128
|
+
**Wire cost vs tiny work.** Round trip is ~100µs; a one-line JS helper
|
|
129
|
+
on three numbers loses to pure Python. Prefer Python (or a native CC
|
|
130
|
+
module) for small/hot work; use the bridge when Node/npm owns the kernel.
|
|
131
|
+
Multi-core: `python -m cc_node.benchmarks.multi_domain` (~2.8× on 3
|
|
132
|
+
domains here).
|
|
133
|
+
|
|
134
|
+
## Choosing node
|
|
135
|
+
|
|
136
|
+
1. `create(node='/path/to/node')`
|
|
137
|
+
2. `CC_NODE_BIN`
|
|
138
|
+
3. `node` on `PATH`
|
|
139
|
+
|
|
140
|
+
Packages: cwd `node_modules`, same as Node itself.
|
|
141
|
+
|
|
142
|
+
From Concurrent-C (not Python): `cc_js_new(false, &a)` hosted
|
|
143
|
+
(libnode), or `cc_js_new(true, &a)` for this wire —
|
|
144
|
+
[`jsdemo.shcc`](https://github.com/sreekotay/concurrent-c/blob/main/examples/js/jsdemo.shcc).
|
|
145
|
+
|
|
146
|
+
## Publishing
|
|
147
|
+
|
|
148
|
+
**PyPI Trusted Publishing (OIDC)** — no API token:
|
|
149
|
+
|
|
150
|
+
1. [Publishing settings](https://pypi.org/manage/project/concurrent-c-node/settings/publishing/):
|
|
151
|
+
owner `sreekotay`, repo `concurrent-c`, workflow `publish-cc-node.yml`,
|
|
152
|
+
environment `pypi`
|
|
153
|
+
2. GitHub Environment `pypi`
|
|
154
|
+
3. Bump `pyproject.toml`, push, then:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
gh workflow run publish-cc-node.yml
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Local / npm sibling:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
./scripts/publish_bridges.sh --publish --minor
|
|
164
|
+
gh workflow run publish-cc-node.yml
|
|
165
|
+
# twine fallback: … --pypi-twine
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Examples: `use_node`, `bench_wire`, `benchmarks.multi_domain`.
|
|
169
|
+
Stress: [`stress/bridge/`](https://github.com/sreekotay/concurrent-c/tree/main/stress/bridge).
|
|
170
|
+
Own hot path in C/CC → native module (40–90ns) —
|
|
171
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: concurrent-c-node
|
|
3
|
+
Version: 0.17.0
|
|
4
|
+
Summary: JavaScript and npm packages from Python over the Concurrent-C bridge: one spawned Node child per domain, host-controlled lifetime.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/sreekotay/concurrent-c
|
|
7
|
+
Project-URL: Documentation, https://github.com/sreekotay/concurrent-c/blob/main/pypi/cc-node/README.md
|
|
8
|
+
Keywords: javascript,node,npm,interop,concurrent-c
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# concurrent-c-node
|
|
13
|
+
|
|
14
|
+
Call Node (and npm packages) from Python.
|
|
15
|
+
Native types, exceptions, callbacks, and async all cross the boundary.
|
|
16
|
+
|
|
17
|
+
Part of [Concurrent-C](https://github.com/sreekotay/concurrent-c) — a
|
|
18
|
+
strict C11-superset preprocessor: `.ccs` lowers to plain C and compiles
|
|
19
|
+
with your host C compiler. (This bridge itself is pure Python stdlib —
|
|
20
|
+
no native build.)
|
|
21
|
+
|
|
22
|
+
Map of the three boundaries (CC hosts JS, native modules, this package
|
|
23
|
+
bridge):
|
|
24
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import cc_node
|
|
28
|
+
|
|
29
|
+
js = cc_node.create() # always a child `node` process
|
|
30
|
+
_ = js.require('lodash') # cwd node_modules
|
|
31
|
+
_.chunk([1, 2, 3, 4, 5], 2) # [[1, 2], [3, 4], [5]]
|
|
32
|
+
|
|
33
|
+
semver = js.require('semver')
|
|
34
|
+
semver.satisfies('1.2.3', '^1.0.0') # True
|
|
35
|
+
|
|
36
|
+
js.destroy() # or: with cc_node.create() as js:
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Unlike [`concurrent-c-python`](https://github.com/sreekotay/concurrent-c/tree/main/npm/cc-python)
|
|
40
|
+
(in-process by default), every `create()` here is a separate Node —
|
|
41
|
+
real addons, crash isolation, measurable wire. N domains = N processes.
|
|
42
|
+
|
|
43
|
+
| | this package | CC hosted (`cc_js_new(false, …)`) |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| API | `cc_node.create()` | `.ccs` program |
|
|
46
|
+
| Where | child `node` | libnode in-process |
|
|
47
|
+
| Hot call | ~105µs RTT | sub-µs (needs libnode) |
|
|
48
|
+
| Bulk | shm (~9.5ms / 8MB) | in-process |
|
|
49
|
+
| Parallelism | N children | one process |
|
|
50
|
+
| Crash | child dies; parent lives | shared fate |
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
pip install concurrent-c-node # needs node on PATH
|
|
54
|
+
python -m cc_node.examples.use_node
|
|
55
|
+
python -m cc_node.examples.bench_wire
|
|
56
|
+
python -m cc_node.benchmarks.multi_domain
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Measured
|
|
60
|
+
|
|
61
|
+
[`bench_wire`](https://github.com/sreekotay/concurrent-c/blob/main/pypi/cc-node/cc_node/examples/bench_wire.py)
|
|
62
|
+
·
|
|
63
|
+
[`cc_node_bridge_py_20260810.txt`](https://github.com/sreekotay/concurrent-c/blob/main/perf/baselines/cc_node_bridge_py_20260810.txt):
|
|
64
|
+
|
|
65
|
+
| what | result |
|
|
66
|
+
|---|---|
|
|
67
|
+
| spawn (first eval) | 28ms |
|
|
68
|
+
| wire RTT | 105µs |
|
|
69
|
+
| Python callback round trip | 153µs |
|
|
70
|
+
| 8MB `array('d')` via shm | 9.5ms |
|
|
71
|
+
| same 8MB as JSON list | 499ms (~52×) |
|
|
72
|
+
|
|
73
|
+
Wire: line-JSON on dedicated fds (stdio stays yours). Bulk spill: private
|
|
74
|
+
0700 dir, 0600 files, removed with the bridge.
|
|
75
|
+
|
|
76
|
+
## Surface
|
|
77
|
+
|
|
78
|
+
- Plain data (numbers, str, bool, `None`, lists, non-empty dicts) by
|
|
79
|
+
value; else a domain-owned handle (attrs, calls, `str()` →
|
|
80
|
+
`String()`). Non-finite floats are tagged.
|
|
81
|
+
- Handles are per-domain. `stats()` / `release()` / idempotent
|
|
82
|
+
`destroy()`; afterwards: `bridge is closed`.
|
|
83
|
+
- Crash isolation, not a sandbox. `destroy()` is cooperative; an
|
|
84
|
+
in-flight CPU-bound call finishes or you kill the child
|
|
85
|
+
([`bridge_stress.md`](https://github.com/sreekotay/concurrent-c/blob/main/stress/bridge/bridge_stress.md)).
|
|
86
|
+
|
|
87
|
+
### Promises
|
|
88
|
+
|
|
89
|
+
Awaited in the child before the reply — no `async`/`await` on the
|
|
90
|
+
Python side (opposite of `concurrent-c-python` isolated):
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
fetchish = js.eval('async (x) => { return { doubled: x * 2 } }')
|
|
94
|
+
fetchish(21) # {'doubled': 42}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Callbacks
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
mapped = js.eval('(f) => [1, 2, 3].map(f)')(lambda x, *rest: x * 10)
|
|
101
|
+
# map passes (value, index, array) — take *rest
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Exceptions cross both ways with messages intact.
|
|
105
|
+
|
|
106
|
+
### Buffers
|
|
107
|
+
|
|
108
|
+
`bytes` / `array.array` / 1-D numpy → typed arrays (and back). Small
|
|
109
|
+
inline; large via shm.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import array
|
|
113
|
+
total = js.eval('(a) => a.reduce((s, x) => s + x, 0)')
|
|
114
|
+
total(array.array('d', range(1_000_000)))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Common issues
|
|
118
|
+
|
|
119
|
+
**`Cannot find module`.** `require` / `import` resolve from the Python
|
|
120
|
+
process cwd (`node_modules` next to your program), not from this wheel’s
|
|
121
|
+
site-packages. `npm install lodash` in the project directory is the fix;
|
|
122
|
+
or `create(node=…)` / `CC_NODE_BIN` when the wrong Node is on `PATH`.
|
|
123
|
+
|
|
124
|
+
### Empty `{}` stays a handle
|
|
125
|
+
|
|
126
|
+
An empty object has to stay on the Node side — a materialized Python
|
|
127
|
+
`dict` would lose later property use that matches Node. So
|
|
128
|
+
`js.eval('({})')` returns a live handle:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
o = js.eval('({})') # JsHandle, not {}
|
|
132
|
+
js.eval('(o) => { o.x = 1; return o.x }')(o) # 1
|
|
133
|
+
js.eval('({a: 1})') # {'a': 1} — data return
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Non-empty plain objects still cross as Python `dict`s. Same-domain
|
|
137
|
+
handles chain (`h.update(…).digest(…)`).
|
|
138
|
+
|
|
139
|
+
**Wire cost vs tiny work.** Round trip is ~100µs; a one-line JS helper
|
|
140
|
+
on three numbers loses to pure Python. Prefer Python (or a native CC
|
|
141
|
+
module) for small/hot work; use the bridge when Node/npm owns the kernel.
|
|
142
|
+
Multi-core: `python -m cc_node.benchmarks.multi_domain` (~2.8× on 3
|
|
143
|
+
domains here).
|
|
144
|
+
|
|
145
|
+
## Choosing node
|
|
146
|
+
|
|
147
|
+
1. `create(node='/path/to/node')`
|
|
148
|
+
2. `CC_NODE_BIN`
|
|
149
|
+
3. `node` on `PATH`
|
|
150
|
+
|
|
151
|
+
Packages: cwd `node_modules`, same as Node itself.
|
|
152
|
+
|
|
153
|
+
From Concurrent-C (not Python): `cc_js_new(false, &a)` hosted
|
|
154
|
+
(libnode), or `cc_js_new(true, &a)` for this wire —
|
|
155
|
+
[`jsdemo.shcc`](https://github.com/sreekotay/concurrent-c/blob/main/examples/js/jsdemo.shcc).
|
|
156
|
+
|
|
157
|
+
## Publishing
|
|
158
|
+
|
|
159
|
+
**PyPI Trusted Publishing (OIDC)** — no API token:
|
|
160
|
+
|
|
161
|
+
1. [Publishing settings](https://pypi.org/manage/project/concurrent-c-node/settings/publishing/):
|
|
162
|
+
owner `sreekotay`, repo `concurrent-c`, workflow `publish-cc-node.yml`,
|
|
163
|
+
environment `pypi`
|
|
164
|
+
2. GitHub Environment `pypi`
|
|
165
|
+
3. Bump `pyproject.toml`, push, then:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
gh workflow run publish-cc-node.yml
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Local / npm sibling:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
./scripts/publish_bridges.sh --publish --minor
|
|
175
|
+
gh workflow run publish-cc-node.yml
|
|
176
|
+
# twine fallback: … --pypi-twine
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Examples: `use_node`, `bench_wire`, `benchmarks.multi_domain`.
|
|
180
|
+
Stress: [`stress/bridge/`](https://github.com/sreekotay/concurrent-c/tree/main/stress/bridge).
|
|
181
|
+
Own hot path in C/CC → native module (40–90ns) —
|
|
182
|
+
[JS / Python interop](https://github.com/sreekotay/concurrent-c/blob/main/docs/js-py-modules.md).
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "concurrent-c-node"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.17.0"
|
|
8
8
|
description = "JavaScript and npm packages from Python over the Concurrent-C bridge: one spawned Node child per domain, host-controlled lifetime."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|