bazel-runfiles 1.9.0


pip install bazel-runfiles

  Latest version

Released: Mar 04, 2026

Project Links

Meta
Requires Python: >=3.7

Classifiers

Development Status
  • 5 - Production/Stable

License
  • OSI Approved :: Apache Software License

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.

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,
    # ...
)
1.9.0 Mar 04, 2026
1.9.0rc1 Feb 23, 2026
1.9.0rc0 Feb 23, 2026
1.8.5 Feb 23, 2026
1.8.4 Feb 11, 2026
1.8.3 Jan 28, 2026
1.8.2 Jan 25, 2026
1.8.1 Jan 21, 2026
1.8.0 Jan 16, 2026
1.8.0rc4 Jan 15, 2026
1.8.0rc3 Jan 11, 2026
1.8.0rc2 Jan 10, 2026
1.8.0rc1 Dec 22, 2025
1.8.0rc0 Dec 20, 2025
1.7.0 Nov 14, 2025
1.7.0rc6 Nov 09, 2025
1.7.0rc5 Nov 06, 2025
1.7.0rc4 Oct 31, 2025
1.7.0rc3 Oct 30, 2025
1.7.0rc2 Oct 29, 2025
1.7.0rc0 Oct 15, 2025
1.6.3 Sep 21, 2025
1.6.1 Sep 08, 2025
1.6.0 Sep 02, 2025
1.6.0rc0 Aug 24, 2025
1.5.4 Aug 28, 2025
1.5.3 Aug 11, 2025
1.5.2 Aug 11, 2025
1.5.1 Jul 06, 2025
1.5.0 Jun 30, 2025
1.5.0rc4 Jun 26, 2025
1.5.0rc3 Jun 25, 2025
1.5.0rc2 Jun 20, 2025
1.5.0rc1 Jun 17, 2025
1.5.0rc0 Jun 12, 2025
1.4.2 Aug 18, 2025
1.4.1 May 08, 2025
1.4.0 May 05, 2025
1.4.0rc4 Apr 29, 2025
1.4.0rc3 Apr 29, 2025
1.4.0rc2 Apr 24, 2025
1.4.0rc1 Apr 22, 2025
1.4.0rc0 Apr 21, 2025
1.3.0 Mar 27, 2025
1.3.0rc1 Mar 21, 2025
1.3.0rc0 Mar 21, 2025
1.2.0 Feb 27, 2025
1.2.0rc1 Feb 22, 2025
1.2.0rc0 Feb 14, 2025
1.1.0 Jan 17, 2025
1.1.0rc1 Jan 13, 2025
1.1.0rc0 Jan 09, 2025
1.0.0 Dec 06, 2024
1.0.0rc2 Nov 29, 2024
1.0.0rc1 Nov 26, 2024
1.0.0rc0 Nov 22, 2024
0.40.0 Nov 17, 2024
0.39.0 Nov 13, 2024
0.38.0 Nov 08, 2024
0.37.2 Oct 27, 2024
0.37.1 Oct 23, 2024
0.37.0 Oct 18, 2024
0.36.0 Sep 24, 2024
0.35.0 Aug 15, 2024
0.34.0 Jul 04, 2024
0.33.2 Jun 19, 2024
0.33.1 Jun 12, 2024
0.33.0 Jun 12, 2024
0.32.2 May 14, 2024
0.32.1 May 13, 2024
0.32.0 May 13, 2024
0.31.0 Feb 13, 2024
0.30.0 Feb 12, 2024
0.29.0 Jan 22, 2024
0.28.0 Jan 08, 2024
0.27.1 Dec 05, 2023
0.27.0 Nov 17, 2023
0.26.0 Oct 06, 2023
0.25.0 Aug 22, 2023
0.24.0 Jul 11, 2023
0.23.1 Jun 13, 2023
0.23.0 Jun 12, 2023
0.22.1 Dec 19, 2023
0.22.0 May 25, 2023
0.21.0 Apr 20, 2023
0.20.0 Mar 20, 2023
0.19.0 Feb 28, 2023
0.18.1 Feb 14, 2023
0.18.0 Feb 08, 2023

Wheel compatibility matrix

Platform Python 3
any

Files in release

No dependencies