Skip to content

About

Python ctypes for Node.js - A high-performance FFI (Foreign Function Interface) library with full Python ctypes compatibility, built on libffi and N-API.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Repository files navigation

node-ctypes

npm version npm downloads Build License: MIT

Python ctypes for Node.js. A foreign function interface built with C++20, node-addon-api and libffi. If you know Python ctypes, you already know node-ctypes.

Support

Development help is welcome: issues, pull requests and discussions are all appreciated.

Tip

If you find node-ctypes useful, consider ⭐ this project and why not ... Buy me a coffee 😄


Quick start

npm install node-ctypes

Prebuilt binaries ship for Windows, macOS 13.5+ and Linux (glibc 2.28+ or musl / Alpine), on x64 and ARM64 — wherever Node 24 runs.

import { CDLL, Structure, c_int32, c_size_t, c_char_p } from "node-ctypes";

// 1. Load a shared library
const libc = new CDLL(process.platform === "win32" ? "msvcrt" : null);

// 2. Declare a function signature
const strlen = libc.strlen;
strlen.argtypes = [c_char_p];
strlen.restype = c_size_t;
console.log(strlen("hello")); // 5n

// 3. Declare a struct
class Point extends Structure {
  static _fields_ = [
    ["x", c_int32],
    ["y", c_int32],
  ];
}
const p = new Point(3, 4);
console.log(p.x, p.y); // 3 4

To build from source, see Getting started.

Supported platforms

Operating system x64 ARM64 Minimum version
Windows ✅ ✅
macOS ✅ ✅ macOS 13.5
Linux, glibc ✅ ✅ glibc 2.28
Linux, musl (Alpine) ✅ ✅

Node.js 24 or later. Details, testing and building from source are in Getting started.


Guides


Examples

Each example in examples/ has its own README; see the index.

  • Electron + React — a native system clock through a sandboxed preload bridge, synchronized C-memory views and a packaged ASAR application
  • Embedded Python — CPython through its C API: code, modules, callbacks, JavaScript objects by reference, shared memory, threads, asyncio and cancellation (Windows, macOS, Linux)
  • Smart card (PC/SC) — winscard on Windows, PCSC.framework on macOS, libpcsclite on Linux
  • Cryptoki (PKCS #11) — complete 3.2 declarations with 2.20–3.2 dispatch and a standalone SoftHSM demo: temporary token, login, RSA, ECDSA, AES and SHA-256
  • Accessibility — macOS UI automation with the Accessibility API
  • COM automation — shell shortcuts (IShellLinkW) and Active Directory (IDirectorySearch)
  • Controls — a small Win32 application with the common controls
  • LDAP — LDAPv3 paged search (wldap32)
  • Registry — setValue / getValue / openKey / deleteKey
  • System tray — tray icon + popup menu

License

MIT. Built with libffi, node-addon-api, and cmake-js.

About

Python ctypes for Node.js - A high-performance FFI (Foreign Function Interface) library with full Python ctypes compatibility, built on libffi and N-API.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages