Skip to main content
Pre-release

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

bazel-runfiles library

This is a Bazel Runfiles lookup library for Bazel-built Python binaries and tests.

Learn about runfiles: read Runfiles guide or watch Fabian's BazelCon talk.

Importing

The Runfiles API is available from two sources, a direct Bazel target, and a pypi package.

Pure Bazel imports

  1. Depend on this runfiles library from your build rule, like you would other third-party libraries:

    py_binary(
        name = "my_binary",
        # ...
        deps = ["@rules_python//python/runfiles"],
    )
    
  2. Import the runfiles library:

        from python.runfiles import Runfiles
    

Pypi imports

  1. Add the 'bazel-runfiles' dependency along with other third-party dependencies, for example in your requirements.txt file.

  2. Depend on this runfiles library from your build rule, like you would other third-party libraries:

    load("@pip_deps//:requirements.bzl", "requirement")
    
    py_binary(
        name = "my_binary",
        ...
        deps = [requirement("bazel-runfiles")],
    )
    
  3. Import the runfiles library:

    from runfiles import Runfiles
    

Typical Usage

Create a Runfiles object and use Rlocation to look up runfile paths:

r = Runfiles.Create()
# ...
with open(r.Rlocation("my_workspace/path/to/my/data.txt"), "r") as f:
    contents = f.readlines()
    # ...

Here my_workspace is the name you specified via module(name = "...") in your MODULE.bazel file (with --enable_bzlmod, default as of Bazel 7) or workspace(name = "...") in WORKSPACE (with --noenable_bzlmod).

The code above creates a manifest- or directory-based implementation based on the environment variables in os.environ. See Runfiles.Create() for more info.

Alternatively, Runfiles.CreateOrRaise() can be used to raise an error instead of returning None if runfiles cannot be found:

r = Runfiles.CreateOrRaise()

If you want to explicitly create a manifest- or directory-based implementation, you can do so as follows:

r1 = Runfiles.CreateManifestBased("path/to/foo.runfiles_manifest")

r2 = Runfiles.CreateDirectoryBased("path/to/foo.runfiles/")

If you want to start subprocesses that access runfiles, you have to set the right environment variables for them:

import subprocess
from python.runfiles import Runfiles

r = Runfiles.Create()
env = {}
# ...
env.update(r.EnvVars())
p = subprocess.run(
    [r.Rlocation("path/to/binary")],
    env=env,
    # ...
)

Metadata

Release files for bazel-runfiles 2.5.0rc3

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

Built distribution (wheel)

Table of built distributions (wheels) for bazel-runfiles 2.5.0rc3
File Interpreter ABI Platform Actions
bazel_runfiles-2.5.0rc3-py3-none-any.whl Python 3 none any Details for bazel_runfiles-2.5.0rc3-py3-none-any.whl

Release files / bazel_runfiles-2.5.0rc3-py3-none-any.whl

Download URL bazel_runfiles-2.5.0rc3-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
313f46fd17ed6c6328f7320632e083d8f1c8e9a68ba80dd3ceceee789a9fc59c
BLAKE2b-256 checksum
How to use checksums
815862b95e54cab05b4f60d6c9e4813b90aa13c5918c35011b5da6b38439d66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for bazel-runfiles 2.5.0rc3

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
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