Skip to main content

callserver

Fast inter-process function calls for Python, with numpy arrays passed through shared memory.

Overview

callserver runs Python functions in another process on the same machine. Large numpy arrays in arguments and return values are moved to shared memory automatically, so they are not pickled or pushed through a pipe. Shared memory is allocated on the first call and reused on every call after that.

It is built for low-latency, high-throughput workloads that need a separate process, such as:

  • Real-time robot control
  • Vision processing pipelines
  • Compute and data-intensive workloads that benefit from zero-copy data sharing

Features

  • Automatic shared memory transfer of large numpy arrays, in both directions
  • Zero-copy transfer with pre-allocated shared memory buffers
  • Synchronous and asynchronous calls, with double-buffering to overlap work
  • Persistent server-side state
  • Runs the server as a child process, or connects to a standalone server over TCP

callserver works on a single machine only. It is not meant for distributed execution.

Installation

pip install callserver

Requires Python 3.8+ and numpy.

Usage

Simple Example

Arrays are transferred via shared memory both ways. No serialization! Shared memory is only allocated the first time the RPC is made. Subsequent calls reuse the same buffers.

import numpy as np
from callserver import CallServer

if __name__ == "__main__":
    # Spawns a child process. np.add runs there; the arrays travel through shared memory.
    with CallServer("adder") as server:
        result = np.zeros((1024, 1024))
        ones = np.ones((1024, 1024))
        for _ in range(100):
            result = server.call(np.add, result, ones)
        print(result[0, 0])  # 100.0

Server-Side State

A context passed to the server (instance or callable) holds state for subsequent calls:

import numpy as np
from callserver import CallServer

class Accumulator:
    def __init__(self, shape):
        self.total = np.zeros(shape)

def accumulate(acc, values):
    acc.total += values
    return acc.total

if __name__ == "__main__":
    # Arguments after the initializer are passed to it on the server.
    with CallServer("accumulator", Accumulator, (512, 512)) as server:
        for _ in range(10):
            total = server.call(accumulate, np.ones((512, 512)))
        print(total[0, 0])  # 10.0

Standalone Server

A server can also run as a separate, long-lived process that clients connect to over TCP. Start it from the command line (the port is required):

callserver --port 5000

Then connect by passing a (name, (address, port)) tuple instead of a name:

import numpy as np
from callserver import CallServer

with CallServer(("adder", ("127.0.0.1", 5000))) as server:
    result = server.call(np.add, np.ones((1024, 1024)), np.ones((1024, 1024)))
    print(result[0, 0])  # 2.0

The server handles one client at a time and keeps running after a client disconnects. Functions sent to it must be importable by the server process.

Server-side functions must be defined at module level so they can be pickled. The if __name__ == "__main__": guard is required on Windows and macOS, because the child process re-imports the main module.

Documentation

  • Usage guide: async calls, double-buffering, pre-allocated buffers, standalone servers, the API reference, and how it works.
  • Examples: runnable scripts.
Example Shows
simple_call.py Basic synchronous call
server_state.py Server-side state with a context initializer
async_calls.py Async calls with double-buffering
preallocated_buffers.py Zero-copy with pre-allocated shared memory
standalone_client.py Connecting to a standalone server

Development

pip install -e .[test]
python -m pytest

License

MIT. See LICENSE.

Metadata

Release files for callserver 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for callserver 0.1.1
File Size Uploaded Provenance Actions
callserver-0.1.1.tar.gz 24.4 kB Without provenance Details for callserver-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for callserver 0.1.1
File Interpreter ABI Platform Actions
callserver-0.1.1-py3-none-any.whl Python 3 none any Details for callserver-0.1.1-py3-none-any.whl

Total release size: 45.6 kB

Release files / callserver-0.1.1.tar.gz

Download URL callserver-0.1.1.tar.gz
Size 24.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3aec597ef4ef34959003594158688cb828eb287f829e6b081f6b000edd84d2a5
BLAKE2b-256 checksum
How to use checksums
009873eaac3d16c6ca30ce0a81a88222e35d379543a1446f73445b359b541c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / callserver-0.1.1-py3-none-any.whl

Download URL callserver-0.1.1-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77bea0578150bf9b2488663c1a1f11c46cf3b14970d94d71ff0852d6673f0160
BLAKE2b-256 checksum
How to use checksums
228df5ef04c58ddadb1a1c8a1b645397c7c2a264e9e500405de44159400b8550
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for callserver 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page