Skip to main content

numba-swig-bridge-rt

numba-swig-bridge-rt is the public runtime used by bridge-enabled downstream SWIG packages. It provides the Numba-facing API used by an application's compiled code; it is not a replacement for the downstream package's normal Python API.

Applications import it as:

import nsb_rt as nsb

Import the downstream package's generated registration module before compiling code that passes its SWIG objects to Numba. The registration module installs the bridge types and its downstream-owned director-state backend.

import nsb_rt as nsb
from numba import njit
from mylibrary import Buffer
import mylibrary.nsb_registration  # installs generated bridge support

@njit
def increment(buffer):
    buffer.Add(1.0)
    return buffer.Value()

buffer = Buffer()
assert increment(buffer) == 1.0

Compiled virtual overrides

For the usual case, subclass the generated SWIG director base directly. After importing mylibrary.nsb_registration, nsb.director finds that base's unique generated binding automatically. Director state is declared in the decorator and is available to @nsb.override methods as normal attributes:

from numba import types
import mylibrary
import mylibrary.nsb_registration  # installs the Evaluator binding

@nsb.director(state={"offset": types.float64})
class OffsetEvaluator(mylibrary.Evaluator):
    @nsb.override("Evaluate", "double")
    def evaluate(self, value):
        return value + self.offset

evaluator = OffsetEvaluator()
evaluator.offset = 0.5
try:
    # Pass evaluator.as_base_proxy() to the downstream library as required.
    # mylibrary.use_evaluator(evaluator.as_base_proxy())
finally:
    evaluator.close()

Use nsb.as_cpointer(array) only inside @njit, and only for immediate calls to a downstream API that does not retain the pointer. Use nsb.own_this, nsb.borrowed_from, and nsb.is_slot_occupied where supported by the downstream generated bridge.

Examples

The usercode_examples/ directory contains end-user examples using the optional sample downstream packages. They all import the public runtime as nsb_rt; none needs the internal generator.

The sample packages are companion distributions in the repository source bundle. They are deliberately not runtime dependencies, so installing numba-swig-bridge-rt alone does not build native samples. From the repository root, install them when you want to run the examples:

python -m pip install ./sample_libraries/*/

The same command works after installing a runtime wheel, provided the repository's sample_libraries/ directory is available.

Downstream packages

The runtime is consumed by downstream packages that ship generated SWIG bridge artifacts. End users install that downstream package and this runtime; they do not need SWIG or the bridge generator. The generator is maintained separately from this public runtime repository and is only needed when developing a new bridge-enabled package.

Metadata

Release files for numba-swig-bridge-rt 0.14.0

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

Source distribution (sdist)

Source distribution for numba-swig-bridge-rt 0.14.0
File Size Uploaded
numba_swig_bridge_rt-0.14.0.tar.gz 56.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for numba-swig-bridge-rt 0.14.0
File Interpreter ABI Platform
numba_swig_bridge_rt-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 129.7 kB

Release files / numba_swig_bridge_rt-0.14.0.tar.gz

Download URL numba_swig_bridge_rt-0.14.0.tar.gz
Size 56.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a8b0c8bcc5f28b4f119f27126358b1bc5000942fb23e2624242b6ba3d509592c
BLAKE2b-256 checksum
How to use checksums
9d07502f38337b7f6b639b431afff1146bac4b452116a85002563af3cda7c2e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / numba_swig_bridge_rt-0.14.0-py3-none-any.whl

Download URL numba_swig_bridge_rt-0.14.0-py3-none-any.whl
Size 73.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbc2c6e3186db3b95c79aa3f94a6ff55e954a9bbb425552c325a30a7af95f6ad
BLAKE2b-256 checksum
How to use checksums
c6ece7081ee3704038b29d2483386507f29a06e5c44919d833a7b75975ad9f39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release history Release notifications | RSS feed

0.15.3

2 release files

This release

0.14.0 This release

2 release files

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