Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

zAPI β€” Make All Programming Languages Talk to Each Other

Project Status: 🚧 Under Active Development β€” Core is stable; English documentation is being gradually translated. Most documentation is currently in Chinese. Please use AI/translation tools to read Chinese docs if needed.

zAPI is a cross-language RPC framework based on pure C ABI, enabling services written in 10+ languages β€” C++, Python, Go, Rust, Java, C#, Pascal, Node.js, and more β€” to call each other as easily as calling local functions.

Core Promise: No IDL, no code generation, no new protocols to learn β€” use your familiar language, call the world.

License: MIT Platform Rust Go Python Java C# C++ Pascal


πŸ“¦ One C ABI, Infinite Possibilities

zAPI is built on a pure C dynamic library. Any language that supports FFI can connect. No IDL, no code generation, no complex configuration β€” just a header file, and your functions can run across languages, processes, and machines.

// Register an API in C
static void __cdecl AddCallback(void* trigger, void* input, void* output) {
    int a, b;
    API_ReadBuffer((TDataHnd)input, &a, sizeof(a));
    API_ReadBuffer((TDataHnd)input, &b, sizeof(b));
    int sum = a + b;
    API_WriteBuffer((TDataHnd)output, &sum, sizeof(sum));
}

int main() {
    API_LoadLibrary();
    TAppHnd app = API_Create_APPHnd("Calc", "Calculator");
    API_Reg_Call(app, "add", "Add two ints", NULL, AddCallback);
    // Prepare network...
    API_Prepare_Service("0.0.0.0", "127.0.0.1:9898");
    API_Prepare_Client("127.0.0.1:9898", app);
    API_Prepare_Done();
    // This API can now be called from any language
}

πŸš€ Key Features

Feature Description
🌍 10+ Language Bindings C++, Python, Go, Rust, Java, C#, Pascal, VB.NET, Node.js, Web.js β€” out of the box
⚑ High Performance IPC mode < 1ms latency, 10,000+ requests/second
πŸ”Œ Dual Communication Modes TCP (cross-machine) + IPC (same-machine microsecond latency)
πŸ”„ Automatic Service Discovery C4-based service mesh with auto-registration, discovery, and load balancing
πŸ›‘οΈ Fault Tolerance & Reconnection Auto-reconnect on disconnect; services re-register automatically
🧡 Full Thread Safety All APIs (except status logging) support concurrent calls
πŸ“¦ Zero-Copy Transfer Direct internal buffer access for maximum performance
🎯 Two Call Modes Request-Response (Call) + One-Way Notification (Notify)
πŸ”§ Zero-Configuration Startup Auto-generates config file on first run; tune without recompilation

🎯 Supported Languages

Language Binding Method Docs Examples
C++ RAII wrapper (API_HubTool.hpp) πŸ“– Guide (CN) 7 examples
C Explicit dynamic loading (API_HubTool.h) πŸ“– Guide (CN) 7 examples
Python ctypes + @expose decorator πŸ“– Complete Guide (CN) 20+ examples
Go CGO bindings πŸ“– Complete Guide (CN) 14 examples
Rust libloading + RAII πŸ“– Guide (CN) 14 examples
Java JNA + AutoCloseable πŸ“– Guide (CN) 4 examples
C# P/Invoke + .NET 8+ πŸ“– Complete Guide (CN) 7 examples
VB.NET P/Invoke πŸ“– Guide (CN) 5 examples
Pascal (Delphi/FPC) external auto-load πŸ“– Complete Guide (CN) 3 examples
Node.js Python gateway proxy πŸ“– Architecture (CN) 1 example
Web.js (Browser) Python gateway proxy πŸ“– Guide (CN) 1 example

Any language that supports the C ABI can be integrated β€” you can even write bindings for your own language.


πŸš€ 5-Minute Quick Start

Step 1: Get the Dynamic Library

Download the appropriate libraries for your platform from Releases:

Platform Core Library IPC Dependency
Windows 64-bit z_api_hub64.dll z_ipc_64.dll
Linux libz_api_hub.so libz_ipc.so
macOS libz_api_hub.dylib libz_ipc.dylib

Place them in your executable directory or system library path.

Step 2: Write a Service in Python

# service.py
from api_hub import Server

app = Server("Calculator")

@app.expose("add")
def add(a: int, b: int) -> int:
    return a + b

if __name__ == "__main__":
    app.start("ipc:calc_service")
    input("Press Enter to stop...")
    app.stop()

Step 3: Write a Client in Go

package main

import (
    "fmt"
    "github.com/PassByYou888/zAPI/api_hub"
)

func main() {
    client, _ := api_hub.NewClient()
    client.PrepareClient("ipc:calc_service")
    client.PrepareDone()

    param, _ := client.CreateDataHnd("add")
    client.WriteInt32(param, 10)
    client.WriteInt32(param, 20)

    result, _ := client.Call("Calculator", param, 3000)
    sum, _ := client.ReadInt32(result)

    fmt.Printf("10 + 20 = %d\n", sum)  // Output: 10 + 20 = 30
}

Run:

# Terminal 1: Start Python service
python service.py

# Terminal 2: Run Go client
go run client.go
# Output: 10 + 20 = 30

Python service called by Go β€” no extra configuration needed.


πŸ“Š Performance Benchmarks

Test Environment: Intel Xeon Gold 6248 / 32GB RAM / Ubuntu 22.04

Communication Mode Avg Latency (p50) Max Throughput Use Case
Same-machine IPC (named pipe) < 0.8 ms ~12,000 req/s Single-node microservices, edge computing
Local TCP loopback ~2.5 ms ~6,500 req/s Development/testing environments
Cross-machine LAN TCP ~5-15 ms Bandwidth-limited Production distributed deployment

Comparison Reference:

Solution Typical Latency Overhead
zAPI (IPC) < 1 ms Baseline
zAPI (TCP) ~2-3 ms +2-3 ms
gRPC (TCP) ~5-8 ms +4-6 ms
HTTP REST (JSON) ~10-20 ms +9-18 ms

Why so fast?

  1. Zero-copy data transfer: API_GetBuffer() returns internal pointers directly
  2. Binary protocol: No JSON/Protobuf encoding/decoding overhead
  3. C-level concurrency scheduling: Callbacks execute in C thread pools, unaffected by Python/Node GILs

🌐 Full Language Interoperability Matrix

Any language client can call any language server:

Server ↓ / Client β†’ C++ Python Go Rust Java C# Pascal Node Web
C++ βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Python βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Go βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Rust βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Java βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
C# βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Pascal βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ… βœ…

πŸ”’ Thread Safety & Callback Execution Context

All zAPI functions (except API_Get_Status) are fully thread-safe. You can call API_Call from thousands of threads concurrently β€” the library handles it all.

But pay attention to callback execution context:

Callbacks (TAPI_Call / TAPI_Notify) execute in background thread pools. This means:

  • ❌ NEVER call API_Call or API_Notify from within a callback β€” may deadlock
  • ❌ NEVER perform long-running blocking operations in callbacks
  • ❌ NEVER directly access UI components from callbacks
  • βœ… Recommended: Offload expensive tasks to your own worker threads asynchronously
// ❌ WRONG: Calling API_Call inside a callback
static void __cdecl BadCallback(void* trigger, void* input, void* output) {
    // DEADLOCK RISK!
    TDataHnd result = API_Call("OtherApp", input, 5000);
}

// βœ… CORRECT: Offload task asynchronously
static void __cdecl GoodCallback(void* trigger, void* input, void* output) {
    // Push request to a queue; worker thread handles it
    WorkQueue.push(input);
    // Return immediately
}

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Application Layer (10+ Languages)            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  C++     β”‚  Python  β”‚  Go      β”‚  Rust    β”‚  Java / C#        β”‚
β”‚  Pascal  β”‚  Node.js β”‚  Web.js  β”‚  C       β”‚  VB.NET           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Unified C ABI Dynamic Library Layer          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              C4 Distributed Service Mesh                        β”‚
β”‚            (Auto-Discovery / Load Balancing)                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         TCP        β”‚        IPC        β”‚   Auto Service        β”‚
β”‚      (Cross-node)  β”‚  (Same-node)      β”‚   Discovery           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

zAPI/
β”œβ”€β”€ Binary/                # Dynamic libraries & executables
β”‚   β”œβ”€β”€ z_api_hub64.dll    # Core dynamic library
β”‚   └── z_ipc_64.dll       # IPC support library
β”œβ”€β”€ C++/                   # C/C++ bindings + examples
β”œβ”€β”€ Py/                    # Python bindings + 20+ examples
β”‚   β”œβ”€β”€ api_hub/           # Python core bindings
β”‚   β”œβ”€β”€ node/              # Node.js gateway
β”‚   └── web/               # Web.js browser gateway
β”œβ”€β”€ Go/                    # Go bindings + 14 examples
β”œβ”€β”€ java/                  # Java bindings + JNA
β”œβ”€β”€ rust/                  # Rust bindings + 14 examples
β”œβ”€β”€ C#/                    # C# bindings + 7 examples
β”œβ”€β”€ VB.NET/                # VB.NET bindings + 5 examples
β”œβ”€β”€ pascal/                # Pascal complete documentation
└── node/                  # Node.js client examples

πŸ“– Documentation

Quick Start (English Overview)

Complete Guides (Chinese β€” Use AI/Translation Tools)

Language Documentation
C++ API Hub Tool C++ Guide
C API Hub Tool C Guide
Python Master Multi-Language Interop from Zero
Go API Hub for Go β€” Complete Guide
Rust zAPI Rust Guide
Java API Hub Java Guide
C# API Hub Tool for C# β€” Complete Guide
VB.NET VB.NET Full-Stack Domination
Pascal API Hub Tool for Pascal β€” Complete Guide
Node.js Node.js Cross-Language Call Architecture
Web.js js_api.py Guide

Architecture Case Studies (Chinese)


🀝 Contributing

We welcome all forms of contribution:

  • πŸ› Report bugs
  • πŸ’‘ Suggest new features
  • πŸ“ Improve documentation
  • πŸ”§ Submit Pull Requests
  • 🌍 Write bindings for more languages

πŸ“„ License

MIT License β€” Free to use, modify, and distribute, even for commercial projects.


⭐ Star Support

If this project helps you, please give us a Star! Your support keeps us motivated.


Make all languages talk to each other.

GitHub Β· Issues Β· Releases

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages