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 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. Use the BUILD_DEPS cmake argument to trigger this build with pip:

CMAKE_ARGS="-DBUILD_DEPS=yes" pip install tuberd

If you prefer to build the dependencies manually, 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 tuberd

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.15.tar.gz (39.7 kB view details)

Uploaded Source

Built Distributions

tuberd-0.15-cp312-cp312-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

tuberd-0.15-cp312-cp312-macosx_11_0_arm64.whl (627.0 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

tuberd-0.15-cp312-cp312-macosx_10_15_x86_64.whl (632.5 kB view details)

Uploaded CPython 3.12 macOS 10.15+ x86-64

tuberd-0.15-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.15-cp311-cp311-macosx_11_0_arm64.whl (633.3 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

tuberd-0.15-cp311-cp311-macosx_10_15_x86_64.whl (638.6 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

tuberd-0.15-cp310-cp310-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

tuberd-0.15-cp310-cp310-macosx_11_0_arm64.whl (631.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

tuberd-0.15-cp310-cp310-macosx_10_15_x86_64.whl (636.5 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

tuberd-0.15-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.15-cp39-cp39-macosx_11_0_arm64.whl (631.7 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

tuberd-0.15-cp39-cp39-macosx_10_15_x86_64.whl (636.8 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

tuberd-0.15-cp38-cp38-manylinux_2_31_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.31+ x86-64

tuberd-0.15-cp38-cp38-macosx_10_15_x86_64.whl (636.6 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tuberd-0.15.tar.gz
Algorithm Hash digest
SHA256 d9a282b324cbb6961da7c5316204a2321926564f68178b1b67400e98cc6f216a
MD5 7499e28f585fa3519ba6cabf721f3740
BLAKE2b-256 56dd1cebac2f56b637903135233566758909c867621833c912583cc8fbe02422

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2797b388f97663cc2acb4f614151ba3f0a43d4804772c4d8e748a798c6b140b1
MD5 9100e0bbf4bad73f759a3bc3459b98c5
BLAKE2b-256 91752beede45542bbed463aefb9d042c5145760a50968e21a39e32aa3e8288d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86755ae5cd1c3a06a47c5026fb7eeaea0ceae036bb51491fbeee1c9edb7c3969
MD5 9289da035bbda90cf0dbddae9b4f4ee7
BLAKE2b-256 32ab4694e54933927fec2323d859ea98f8619714cd7702c963a786f3144ebfbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp312-cp312-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 73dace56f2b52fabadbfcd5a8363950106a22b960364cbee7a22953db686bb5a
MD5 82f18dfebdac43328c8446892c4502dd
BLAKE2b-256 6972b5c1fd246cc8ea26b28495384147d579743d92f0a3d5b375a6ccc5b3b03c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a3e95ab470f6e104a2ed08ee04759e08f42eb807485a930830aa806184186e41
MD5 5d3e87e7423d615c17be334ed7f5ae58
BLAKE2b-256 7f98e04aa6d9e64ff1206fd9ff89fd47b4d92297ad29e401fca88ecbd4460060

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd16c843315a21ae5504b8bfceee8515e38e19278d89a3c5d91ff9d4cd42bea4
MD5 090e0e24df5561ad0ca7b204660bfdb4
BLAKE2b-256 8d00f13be5b09520e436098bf362ae3efb0178aba815024b5ddabce2cbba5abe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3dd32fa11f834dc7ee2b0f0b72f50be231e4c36a5d21c8649e8dcb4085ff3b17
MD5 cae4f8dca48588d5423ad9ba8660296a
BLAKE2b-256 8bb34a958f11140b110d750b9658a0b7fae50090a7f7eb6c0996f01d5506a36b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 c1ba7658aa74e3c02c86c1cbbcd74a7044d6821e9793ad21c2387bfaee0f4e98
MD5 9080ecd282e9b8fd7e9369981cef1b03
BLAKE2b-256 e1a874afdd1c35d45b4ca3ee3d196651d320e7dc3672c650f35408e2891e7bfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75ffc7155ee231e46efa28e16a97fe0dd7d5981f6ed79b3d795881a9901b104d
MD5 48e4ae3f536ca3ebdbcf3b1a0f97fa85
BLAKE2b-256 292bddcae48be316401968de7afe43168171f24c1deed4f6be12b7e1a9838883

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 252dedddf5ef10a12cf0bb7cb01bac46542a1d7dc757e621a177837140e40286
MD5 8433052f6edf1c07bf7aadddae83e495
BLAKE2b-256 a926fd768839dececf58f3b7bcc2c545fa943a2eafe6a88115ff6d3d8ca01d77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 af470bef5c08551d96af247157dc48796734e18384946b73ceda470e4b4deb0e
MD5 bf7a26a8793e5bd1055561b270dcf6a3
BLAKE2b-256 2ffd367b3d8c1890035d63a3fcfc4ed75b02d2367748b264125a03b88f36fa12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8cb86de8ccd96a0d95c83cb47558d36811c616124c6d3a4780f93a0f6f8345c
MD5 6bb044e7272d578a1c3ed13980a383ae
BLAKE2b-256 4b9cb96476e43b4247a7998d3ad8604bad00b7f7ee31049a77dac03dd5639ed2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4e783808f5d57390569da0f9703c80ef406dfddd017d60d17cdca8ef42d56ec6
MD5 00ce1b52faabec7ac5a8023520c6d1ad
BLAKE2b-256 00879bda33fe3788c76184053b6df921b37639420e18d6e37ddc9ce70919de54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 38f6bc073e0a3821ee3aee7f640e0b4b1f1cd9475e809874a6ef223a9ee135e0
MD5 348ff95cac763046b595eeb355bf26d6
BLAKE2b-256 eb38ea924b244aff92671b295860a5e5db6b8a86d33e53f12d41f11051994d2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tuberd-0.15-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0222f8a72ac540312fb8fa7e63b1a896d3866adaaad211c94d3f6e9dee30f1c3
MD5 ecb2753c3a6ebc8d5cf64da39bb285cf
BLAKE2b-256 ff9944af27424d95c0c26cfe7a8f3a838601a862050ea6ab834c678d8c6a5ef5

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