Skip to main content

concurrent-c-node

JavaScript — and every npm package — from Python.

Part of Concurrent-C — a strict C11-superset preprocessor: .ccs lowers to plain C and compiles with your host C compiler. (This bridge itself is pure Python.)

Map of the three boundaries (CC hosts Python, native modules, this package bridge): JS / Python interop.

import cc_node

js = cc_node.create()                # an Isolation Domain: one node child
_ = js.require('lodash')             # resolved from YOUR cwd's node_modules
_.chunk([1, 2, 3, 4, 5], 2)          # [[1, 2], [3, 4], [5]]
_.sortBy([{'n': 3}, {'n': 1}], 'n')  # dicts cross as objects, and back

semver = js.require('semver')
semver.satisfies('1.2.3', '^1.0.0')  # True

js.destroy()                         # or: with cc_node.create() as js: ...

The bridge is pure Python, stdlib only — no compiled code, no dependencies, nothing to build. The domain is a spawned node child (~28ms to first call), so you get real Node: full stdlib, native addons, whatever npm installs. Promise-based APIs look synchronous from Python, and bulk data crosses through shared memory — an 8MB array in 9.5ms where the same values as a JSON list take 499ms.

pip install concurrent-c-node   # needs node on PATH (or point at one)
python -m cc_node.examples.use_node
python -m cc_node.examples.bench_wire

Import stays import cc_node. Examples ship in the wheel. The mirror of concurrent-c-python — same domain model, same materialization rules, pointed the other way:

  • Values: plain data (finite numbers, strings, booleans, None, lists/dicts of the same) crosses by value; everything else is a live handle owned by the domain — attribute access is property lookup (methods arrive bound), calls are calls, str() is String(). Non-finite floats cross tagged, never silently nulled.
  • The domain rules hold: handles never cross bridges; stats() is the handle ledger and release() drops one early; destroy() is idempotent, every door answers bridge is closed after, and the child dies with the bridge (and on host exit, via wire-fd EOF). Teardown is cooperative (farewell close + drain, then wait / kill-fallback): in-flight calls may still return a correct value. There is no clean cancel of CPU-bound JS work — wait, or kill the child (SIGKILL / process.abort) and create a new domain. Hard death must reject in-flight ops. See bridge_stress.md.

Async is free

A thenable result is awaited in the child before the reply, so promise-based package APIs need nothing special — no event loop on the Python side, no await:

fetchish = js.eval('async (x) => { return { doubled: x * 2 } }')
fetchish(21)                         # {'doubled': 42} — just a call

Whatever an npm package's API returns — value or promise — the call site reads the same.

Callbacks: Python functions as JS functions

A Python callable passed as an argument crosses as a JS function, and may be called back any number of times — including from inside async JS code:

mapped = js.eval('(f) => [1, 2, 3].map(f)')(lambda x, *rest: x * 10)
# [10, 20, 30] — JS conventions apply: map passes (value, index, array),
# so a lambda takes *rest.  Exceptions cross both ways, messages intact.

Nested callbacks compose (the wire alternates strictly), and a Python exception inside one surfaces as the JS error at the call site — and vice versa.

Buffers: typed arrays, shared memory

bytes, array.array, and 1-D numpy arrays cross as Float64Array / Int32Array / Uint8Array / … and come back as numpy arrays (or array.array without numpy):

import array
total = js.eval('(a) => a.reduce((s, x) => s + x, 0)')
total(array.array('d', range(1_000_000)))   # crosses via shared memory

Small buffers inline; big ones spill through shared memory — one memcpy per side, the receiver consumes the spill file, and the sender sweeps it if the child died first. Nothing strays, and nothing is silently truncated: an unsupported type is an articulate error.

Choosing the node

Same ambient-first rule as the rest of the family: the domain runs whatever node your project runs.

  1. create(node='/path/to/node') from code — per-domain.
  2. CC_NODE_BIN in the environment.
  3. node on PATH.

And which packages it sees is the working directory's node_modulesrequire resolves exactly as node itself would there. Run Python in your project, get your project's packages: npm install next to your program is the whole setup.

(Writing Concurrent-C itself rather than Python? There is a zero-IPC tier: cc_js_new(false, &a) boots libnode inside your CC program — see examples/js/jsdemo.shcc.)

Publishing

From the Concurrent-C repo root (packs this wheel and the npm sibling):

./scripts/publish_bridges.sh              # → out/pypi/concurrent_c_node-* (+ npm tgz)
./scripts/publish_bridges.sh --publish    # bump patch, pack, twine + npm publish

Measured

From python -m cc_node.examples.bench_wire (sources under cc_node/examples/) on a 4-vCPU x86-64 box, node 22 / python 3.11 (perf/baselines/cc_node_bridge_py_20260810.txt; catalog: perf/baselines/README.md):

what result
spawn a domain (node child, first eval) 28ms
wire round trip (smallest call) 105µs
Python-callback round trip (JS → Python → JS) 153µs
8MB array('d') argument, shm spill 9.5ms
the same 8MB as a JSON list 499ms — the spill is 52x

The wire is strict request/response JSON on dedicated fds — replies pair by request id, and stdio stays yours, so console.log in evaluated JS reaches the real stdout and can never collide with a protocol reply — with the shared-memory spill for bulk data (private 0700 per-bridge directory, 0600 exclusive-create files, removed with the bridge). The same discipline concurrent-c-python's isolated domains speak, mirrored. True pinned zero-copy leases remain future work.

One boundary, stated plainly: the domain is crash isolation, not a security sandbox — the node child inherits your environment and runs with your OS privileges, so do not run untrusted JavaScript through it.

A worked tour (builtin Node modules, chains, callbacks, thenables, buffers — no npm install needed): python -m cc_node.examples.use_node.

Adversarial multi-child storm (escaped closures, cooperative fanout-destroy, abort inject, handle-leak / RSS soaks): stress/bridge/./stress/bridge/run.sh (CHAOS_SCALE=full / soak for bigger N). Mode catalog + destroy contracts: bridge_stress.md (latency demos stay in cc_node/examples/).

And when the hot path is YOUR code rather than an npm package, skip the wire entirely: a page of Concurrent-C (or C) exports as a native module for Python and Node both — 40-90ns calls, stable-ABI artifacts. See Native modules for Node and Python.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

concurrent_c_node-0.10.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

concurrent_c_node-0.10.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file concurrent_c_node-0.10.0.tar.gz.

File metadata

  • Download URL: concurrent_c_node-0.10.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for concurrent_c_node-0.10.0.tar.gz
Algorithm Hash digest
SHA256 2e1d70b3ac934aa6de62a090763bb37d277016a1a9173ee68f809078c177bd56
MD5 fe7f60052a441f0159f9a7c0efc42e0d
BLAKE2b-256 89960b0ec8ad145af8730c5d0c7975a98b7477008cd07de34cce3b583a446dbc

See more details on using hashes here.

File details

Details for the file concurrent_c_node-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for concurrent_c_node-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84cc0b09d758d1e5dd1288827c0437b23e38975d0d1fa37848dd9abcfb5d0ca9
MD5 e9e8f64da7da85abd5bc3348750f4624
BLAKE2b-256 e4d25f6b38017e3fb897812290c711f1c9a19f62e410c41c3c314d4756bd89da

See more details on using hashes here.

Release history Release notifications | RSS feed

0.23.3

2 files

0.23.2

2 files

0.23.1

2 files

0.23.0

2 files

0.22.1

2 files

0.22.0

2 files

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.0

2 files

0.17.11

2 files

0.17.10

2 files

0.17.9

2 files

0.17.8

2 files

0.17.7

2 files

0.17.6

2 files

0.17.5

2 files

0.17.4

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.12.0

2 files

0.11.0

2 files

This release

0.10.0 This release

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page