Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

baml_bridge

Python bindings for the BAML runtime (powered by bex_engine).

baml_bridge is the bridge layer that generated baml_sdk packages import at runtime: it provides the BamlRuntime singleton, the protobuf encoder/decoder and the function/method factories.

from baml_bridge import BamlRuntime

rt = BamlRuntime.initialize_runtime(
    root_path=".",
    files={"main.baml": baml_source},
)

This package is generally consumed indirectly via the code generated by baml-cli generate --target python — direct use is reserved for runtime authors and bridge tests.

Package name and location

The generated SDK never names its own package, so it imports under whatever name and location it is installed at. package_name in the generator section picks both: by default the SDK is baml_sdk in output_dir. A library that ships a generated SDK can nest it inside its own package, so it does not install a top-level baml_sdk that another library's SDK would overwrite:

[generator.python]
output_type = "python/pydantic"
naming_convention = "language"
output_dir = "src"                     # the import root
package_name = "my_app._generated"     # written to src/my_app/_generated

BAML creates missing parent directories but never writes or edits my_app/__init__.py. One process still holds one BAML program: two generated SDKs imported into the same process replace each other's program.

Python callback execution

Passing a Python callable to BAML uses the environment of the call that invokes it. Reusing a callback across threads, event loops, or requests does not retain its registration environment.

BAML entry Python callback Execution environment
Synchronous Synchronous Calling Python thread, with its current context
Synchronous Coroutine result Bridge-owned worker loop, with copied caller context
Asynchronous Synchronous or coroutine result Originating application loop, with copied entry context

The generated type of a callback parameter or class field accepts both forms: typing.Callable[[...], typing.Union[R, typing.Coroutine[typing.Any, typing.Any, R]]], so a type checker takes a plain function and an async def for it.

A class has one type for a field, whoever built the instance. A call of a function-typed field therefore has the type R | Coroutine[Any, Any, R] also on an instance that BAML returned, where the callable is a BAML closure and the call returns a coroutine of R. A function that BAML returns directly, and a callable that BAML passes to a callback, is typed as the BAML closure it is: like a generated function, await closure(...) gives R, optional parameters are keyword-only, and the blocking closure.call_sync(...) returns R directly.

Each dispatch of an async entry receives a separate copy of its application ContextVars. Callback writes do not change the awaiting task's context or another dispatch's context. An async callback need not run in the caller's exact asyncio.Task.

A synchronous entry blocks its calling thread, including any application loop running there. Coroutine callbacks of that entry must use resources of their executing worker loop. Awaiting resources owned by the blocked loop is unsupported.

Returned BAML closures support await closure(...) and the blocking closure.call_sync(...). Passing a closure back into BAML preserves its native function handle. Each new invocation selects its own environment.

Cancelling a BAML call cancels executing coroutine callbacks on their owning loops. Callback tasks retain their arguments and context until their bodies and async cleanup finish. Cancellation does not interrupt a synchronous Python body. A callback that suppresses cancellation may finish later; its result does not revive the cancelled BAML call.

Unobserved errors of spawned tasks

A BAML spawn { ... } task can end with an error that no code awaits. The runtime finds such a task at a later garbage collection or at shutdown, and reports its error one time to one handler for the process. The default handler prints the traceback and ends the process, as an uncaught exception ends a script (exit status 1; on Windows the process terminates itself with SIGTERM). If the task was cancelled, the default only prints.

A server must usually not end because of one stray task. It installs a handler that reports the error and returns:

import logging

import baml_bridge


def report(error: BaseException, cancelled: bool) -> None:
    logging.getLogger("baml").error("unobserved BAML spawn error", exc_info=error)


baml_bridge.set_unhandled_spawn_error_handler(report)
  • error is the exception that a call raises for the same failure (a BamlError, a BamlPanic, or the exception a Python callback raised). Its traceback has the BAML frames. cancelled is True when the task was cancelled: its cancellation fired before it failed, or cancel() was called on it at any time, also after it failed.
  • The handler runs on a thread of the BAML runtime, not on the thread or the event loop that made the call, and no event loop runs on that thread. It must return soon and must not call BAML. To reach the application, use loop.call_soon_threadsafe or a queue.
  • If the handler raises, the bridge prints the error of the task, gives the exception of the handler to sys.unraisablehook, and the process continues.
  • set_unhandled_spawn_error_handler returns the handler that it replaces. None restores default_unhandled_spawn_error_handler. A handler can call the default for the errors that must end the process.

Thrown values with no Python class

A BamlError or BamlPanic carries the thrown BAML value as .value. Where the generated SDK has a class for it, .value is an instance of that class. A thrown value can also be of a class that has no Python class: a process that uses baml_bridge with no generated SDK has none, and a program can make a class at run time. Such an instance is a baml_bridge.BamlClassInstance:

try:
    call_function_sync(runtime, "missing", {}).result()
except BamlError as error:
    error.class_name                # "baml.errors.InvalidArgument"
    error.value.class_name          # the same name, also on a nested instance
    error.value.fields["message"]   # fields under their BAML names

A returned value is different: it has a declared type that a typed caller relies on, so a returned instance of a class with no Python class is an error.

Requirements

  • Python 3.10+
  • protobuf >= 6.31.1

License

Apache-2.0

Metadata

Release files for baml-bridge 0.25.3.dev2026111600

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

Built distributions (wheels)

Table of built distributions (wheels) for baml-bridge 0.25.3.dev2026111600
File Actions
baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_arm64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_amd64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_x86_64.whl CPython 3.10 abi3 Linux musl 1.1+ x86-64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_x86_64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_aarch64.whl CPython 3.10 abi3 Linux musl 1.1+ ARM64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_aarch64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux_2_24_aarch64.whl CPython 3.10 abi3 Linux glibc 2.24+ ARM64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux_2_24_aarch64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_11_0_arm64.whl
baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 135.1 MB

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_arm64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_arm64.whl
Size 17.2 MB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
ca9502a29cb9c252f5b2c935ce7a03a743105c9b1a3ad4dd251b5c9cef61fe47
BLAKE2b-256 checksum
How to use checksums
810e0f8d18fd0cf58b13925e0255c5eff3882487973d2c8828eb81bc4a96df5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_amd64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_amd64.whl
Size 18.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
19dd96e3943fa5250f9eeb2d50eb3751df3f872762f217d264f9eeb9e8a315f7
BLAKE2b-256 checksum
How to use checksums
7221ed8e9eb79d1d8355523e4dc16b8df005914aaa4c39da8e07648e7e0bd2ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_x86_64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_x86_64.whl
Size 17.4 MB
Tags CPython 3.10 Linux musl 1.1+ x86-64 abi3
SHA-256 checksum
How to use checksums
d51ef080b4418c1d18e1bdcd7b3a268f6f07a2ef54808c50df89f284057f0766
BLAKE2b-256 checksum
How to use checksums
14f46ce457d69849259887b4f33f87872923bbde6b246013bf5e465addfb018e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_aarch64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-musllinux_1_1_aarch64.whl
Size 16.3 MB
Tags CPython 3.10 Linux musl 1.1+ ARM64 abi3
SHA-256 checksum
How to use checksums
24b776de17c69a7d3fa75a58ded9e6991b42a13e505d46998c581e7625e4fb16
BLAKE2b-256 checksum
How to use checksums
eae6517c053d5670f2412fba3308c494bc4ddc81187946d5f357019f58de2e1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux_2_24_aarch64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux_2_24_aarch64.whl
Size 16.1 MB
Tags CPython 3.10 Linux glibc 2.24+ ARM64 abi3
SHA-256 checksum
How to use checksums
f007d3df8e94532cb1755a7e0275cbe1d16822b94e0132847571c87f02cd391e
BLAKE2b-256 checksum
How to use checksums
f3bb777509313080a8e2f8b21a0acb4f173f6cb08d8c9d215dce34f8c5981ff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 17.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
298a866657a441fac5576c044b254271abaa72b05c934a9cff09cfd676db258f
BLAKE2b-256 checksum
How to use checksums
b0589c04ef4ddea41fa5d4b3628fee9a21b2dc512366e1b98072675489e01538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_11_0_arm64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_11_0_arm64.whl
Size 15.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
45b907565302830da3af14a5c3e23dae55fa46da8ed2abefbbf97a2a9a485b2d
BLAKE2b-256 checksum
How to use checksums
3a0e30521cf41bdca27c7ea7edc6cb208ae2a663157ef17db4a496ff4e73a53f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_10_12_x86_64.whl

Download URL baml_bridge-0.25.3.dev2026111600-cp310-abi3-macosx_10_12_x86_64.whl
Size 16.8 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8e7c3c9d28e6fef38f5c1913dd90d33a9bfd645901edd935ab9069cebc319237
BLAKE2b-256 checksum
How to use checksums
4d2fe8e6593b7b99cb4d25ecdd95ca529de4170f127c8f8c96ee549733ccf644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for baml-bridge 0.25.3.dev2026111600

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.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for baml_bridge-0.25.3.dev2026111600-cp310-abi3-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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

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