Skip to main content

Serve Python (or C++) objects across a LAN using something like JSON-RPC

Project description

https://badge.fury.io/py/tuberd.svg https://github.com/gsmecher/tuberd/actions/workflows/package.yml/badge.svg

Tuber Server and Client

Tuber is a C++ server and Python client for exposing an instrumentation control plane across a network.

On a client, you can write Python code like this:

>>> some_resource.increment([1, 2, 3, 4, 5])
[2, 3, 4, 5, 6]

…and end up with a remote method call on a networked resource written in Python or (more usually) C++. The C++ implementation might look like this:

class SomeResource {
public:
    std::vector<int> increment(std::vector<int> x) {
        std::ranges::for_each(x, [](int &n) { n++; });
        return x;
    };
};

On the client side, Python needs to know where to find the server. On the server side, the C++ code must be registered with pybind11 (just as any other pybind11 code) and the tuber server. Other than that, however, there is no ceremony and no boilerplate.

Its main features and design principles are:

  • Pythonic call styles, including *args, **kwargs, and DocStrings.

  • JSON and CBOR support for efficient and friendly serialization of return values.

  • “Less-is-more” approach to code. For example, Tuber uses pybind11 and C++ as a shim between C and Python, because the combination gives us the shortest and most expressive way to produce the results we want. It pairs excellently with orjson (as a JSON interface) or cbor2 (as a CBOR interface), which efficiently serialize (for example) NumPy arrays created in C++ across the network.

  • Schema-less RPC using standard-ish protocols (HTTP 1.1, JSON, CBOR, and something like JSON-RPC). Avoiding a schema allows server and client code to be independently and seamlessly up- and downgraded, with differences between exposed APIs only visible at the sites where RPC calls are made.

  • A mature, quick-ish, third-party, low-overhead, low-prerequisite embedded webserver. Tuber uses libhttpserver, which in turn, is a C++ wrapper around the well-established libmicrohttpd. We use the thread-per-connection configuration because a single keep-alive connection with a single client is the expected “hot path”; C10K-style server architectures wouldn’t be better.

  • High performance when communicating with RPC endpoints, using:

    • HTTP/1.1 Keep-Alive to avoid single-connection-per-request overhead. See this Wikipedia page for details.

    • A call API that (optionally) allows multiple RPC calls to be combined and dispatched together.

    • Client-side caches for remote properties (server-side constants)

    • Python 3.x’s aiohttp/asyncio libraries to asynchronously dispatch across multiple endpoints (e.g. multiple boards in a crate, each of which is an independent Tuber endpoint.)

  • A friendly interactive experience using Jupyter/IPython-style REPL environments. Tuber servers export metadata that can be used to provide DocStrings and tab-completion for RPC resources.

  • The ability to serve a web-based UI using static JavaScript, CSS, and HTML.

Anti-goals of this Tuber server include the following:

  • No authentication/encryption is used. For now, network security is strictly out-of-scope. (Yes, it feels naïve to write this in 2022.)

  • The additional complexity of HTTP/2 and HTTP/3 protocols are not justified. HTTP/1.1 keep-alive obviates much of the performance gains promised by connection multiplexing.

  • The performance gains possible using a binary RPC protocol do not justify the loss of a human-readable, browser-accessible JSON protocol.

  • The use of newer, better languages than C++ (server side) or Python (client side). The instruments Tuber targets are likely to be a polyglot stew, and I am mindful that every additional language or runtime reduces the project’s accessibility to newcomers. Perhaps pybind11 will be eclipsed by something in Rust one day - for now, the ability to make casual cross-language calls is essential to keeping Tuber small. (Exception: the orjson JSON library is a wonderful complement to tuber and I recommend using them together!)

Although the Tuber server hosts an embedded Python interpreter and can expose embedded resources coded in ordinary Python, it is intended to expose C/C++ code. The Python interpeter provides a convenient, Pythonic approach to attribute and method lookup and dispatch without the overhead of a fully interpreted embedded runtime.

Tuber is licensed using the 3-clause BSD license (BSD-3-Clause). This software is intended to be useful, and its licensing is intended to be pragmatic. If licensing is a stumbling block for you, please contact me at gsmecher@threespeedlogic.com.

Installation

Pre-built wheels for Linux and macOS operating systems are available on PyPI for CPython 3.8+:

pip install tuberd

Building from source requires the libfmt and libmicrohttpd dependencies, along with libhttpserver. To ensure that cmake can find the libhttpserver library, you may need to add the path where the FindLibHttpServer.cmake file is installed to the CMAKE_MODULE_PATH option, for example:

CMAKE_ARGS="-DCMAKE_MODULE_PATH=/usr/local/share/cmake/Modules" pip install .

To simplify the build process, the wheels/install_deps.sh script can be used to build all the dependencies locally and compile against them. In this instance, cmake should be able to discover the appropriate paths for all dependencies:

./wheels/install_deps.sh
pip install .

Project details


Download files

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

Source Distribution

tuberd-0.14.tar.gz (38.6 kB view details)

Uploaded Source

Built Distributions

tuberd-0.14-cp312-cp312-manylinux_2_31_x86_64.whl (1000.0 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

tuberd-0.14-cp312-cp312-macosx_11_0_arm64.whl (625.5 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

tuberd-0.14-cp312-cp312-macosx_10_15_x86_64.whl (631.1 kB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

tuberd-0.14-cp311-cp311-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

tuberd-0.14-cp311-cp311-macosx_11_0_arm64.whl (631.9 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

tuberd-0.14-cp311-cp311-macosx_10_15_x86_64.whl (637.1 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

tuberd-0.14-cp310-cp310-manylinux_2_31_x86_64.whl (999.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

tuberd-0.14-cp310-cp310-macosx_11_0_arm64.whl (630.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tuberd-0.14-cp310-cp310-macosx_10_15_x86_64.whl (635.1 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

tuberd-0.14-cp39-cp39-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.31+ x86-64

tuberd-0.14-cp39-cp39-macosx_11_0_arm64.whl (630.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

tuberd-0.14-cp39-cp39-macosx_10_15_x86_64.whl (635.4 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

tuberd-0.14-cp38-cp38-manylinux_2_31_x86_64.whl (999.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.31+ x86-64

tuberd-0.14-cp38-cp38-macosx_10_15_x86_64.whl (635.2 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file tuberd-0.14.tar.gz.

File metadata

  • Download URL: tuberd-0.14.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for tuberd-0.14.tar.gz
Algorithm Hash digest
SHA256 30f3a0d89be1ac4be8d1fd71d19178cd794f58cd622f6fd15109726df5ddbfdf
MD5 5f7eb000c36a36c5295d4d6eeaeedb22
BLAKE2b-256 8f607b960f9c770405dde98d69d50c727c13c2af31c4d57d9da543e2b31e3c8a

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 6de7514c9514027035ed251bd248004dfc2e19e34d27e473cccf067c4ba8510e
MD5 06a397a2e9adee4ec64f60273e449bad
BLAKE2b-256 f6d15290af4778375517db2c81485e30a448efcdb53e310ca213c524a2848804

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f462a14f72006d70a35c8f53be31a3eb2c160e87f0e22f6edf3f8c8ea67c77d7
MD5 37baccd6232a427907b0931ff8bd002e
BLAKE2b-256 0df6d2b8ae7b4c81d32707a412a710d15eb90439afa25d4c6c656fb778dcd650

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp312-cp312-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 22d5d56a224dc2c759dc40f8cafbcea1c8b5c1527a295f8b104d252fa6a31362
MD5 8fb4f3be9616739f3d13fb574c001c74
BLAKE2b-256 5fe6d1ff7ef9519f061102c8b099055da99017ce231a0dcd3bd76d9c352de34f

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a576fa92bba3d9ba05686afba86318981f0680cd4ea3b3ed7987daff94ebbaa9
MD5 e3ba4778905eac224639a9d804967a19
BLAKE2b-256 9b55ef4b4ca85a1f9f8c2f223e73a45eb45149b23f2b406585ee4357130f01e0

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 722bd24e00f35ef8b5a3a746f1b67b6ad1212d2365180e5501ddd65886846e01
MD5 e861a1c5fcc915bd1145cdce1cb3ca42
BLAKE2b-256 b88ecea7264e4b7a5153c23faab330fdccbca21ae46f1730f409858ffba1fca2

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ae9371413ff2ef50948dd412eec9f7cac13ce264459d94963a902c68a2c13c52
MD5 ea38c065695fb2f22f96c8074120e075
BLAKE2b-256 b49e65d3d7f058c294e217b5c7ba8382665e95854ed258700336e4117bef095c

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp310-cp310-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 70ed0309f2b50418b9759d56ea37cd36eaedca74a06ba152f0620702af53fbc5
MD5 7d2cf8881700b8657cc35a2010f93442
BLAKE2b-256 ec52bce6624bc69659cb29e7c13b912527a8443273ca8a0e244cdaab6bcadf50

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b30c745946f8b4edf67fba235ba944cea34cf012bec57df96140da234d5fecd
MD5 39a7e01e55a184afff276be94738e6e2
BLAKE2b-256 835a00719514ddb7eea4794289835117da168ca3b19533a6e852ea44d9349100

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 132ae096fbd211198b8ada7a4933170a8b47bf990184e0409ed2e3aa36a4bf34
MD5 d9833479c07b2398716f4fdc61569f88
BLAKE2b-256 af305656733a40f222b6855acf9804a5f2a6158ff5176738694779554f4f949c

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp39-cp39-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 286a2885ef4f81b50894d669952833096968027bd08bd49268feed0f021ecfed
MD5 da0089395b0eb904dcd2c94e5545e3da
BLAKE2b-256 3ff9f04afc1e87111dc01d369de63653a6c23deb342fd3929ea63e99f9151db7

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e518db1e189ce3cf45ee25e7b631ea4b3b6c382c0e2892d39ff3e5f8a6e1bb49
MD5 5bf6850ebcd6adb0a5c11751d08ef6cc
BLAKE2b-256 5f9823cb3461cb9df47e521e757152753f9b4655bbffc11cd83a4e195187ddf4

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1fb32c9f4e630c8ce0649ead9bb164aaf6ba18a93aaf1293be6733760b7c7c2f
MD5 8d950a40c282c0deb21e0b8c70672a76
BLAKE2b-256 1d1babfd58be9d5badebd03302a57fc37634a9995f393cfa465a651dac71bb72

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp38-cp38-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d629e68e45f6caf570eedf6f1061ec203a6359a5c59ade8fcb62102272ebddb6
MD5 3b08f515ed5df11a07c0967a05def32c
BLAKE2b-256 09f64c4e161bd2f26d2a1151a23ffae485517553b78a45aff997852d4175fc30

See more details on using hashes here.

File details

Details for the file tuberd-0.14-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tuberd-0.14-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e3ba284a4ac51fff5c46e3db376538ca7990883152c4ecf38501436dfb0abe6b
MD5 17d4a57f7369a17dff444526404bb062
BLAKE2b-256 2ac85d84573c305eea18b904077a00df21e90f3082cebbfc4e753d1c411fd1e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page