Clone this repo:
  1. 9fae6b6 Create CODEOWNERS (#118) by Jon Brandvein · 1 year, 10 months ago main master upstream/master
  2. a69d891 Update readme to indicate maintenance status of subpar by Jon Brandvein · 1 year, 10 months ago
  3. 7aa5f9d Propagate tags via par_*** macros (#112) by Andy Scott · 1 year, 10 months ago
  4. 2917d27 Load Python rules from bazelbuild/rules_python (#115) by Jon Brandvein · 1 year, 11 months ago
  5. 35bb9f0 Add note on bazel version compatibility to WORKSPACE (#107) by Jon Brandvein · 2 years, 1 month ago 2.0.0


Build Status

Subpar is a utility for creating self-contained python executables. It is designed to work well with Bazel.


Subpar is currently owned by the maintainers of bazelbuild/rules_python, which depends on it. It is not being actively developed beyond what is needed to keep compatibility with rules_python.

Historically, subpar was the only way to produce a deployable Python artifact in Bazel. This is no longer quite true; --build_python_zip allows you to create executable Python zip artifacts with the standard py_binary rule. Subpar still supports some use cases --build_python_zip doesn't: In particular, it allows you to build archives of specific targets without using a global command-line flag, and in some cases the archives can run in-place without extraction.


  • Add the following to your WORKSPACE file:
    name = "subpar",
    remote = "",
    tag = "1.0.0",
  • Add the following to the top of any BUILD files that declare par_binary() rules:
load("@subpar//:subpar.bzl", "par_binary")


par_binary() is a drop-in replacement for py_binary() in your BUILD files that also builds a self-contained, single-file executable for the application, with a .par file extension.

To build the .par file associated with a par_binary(name=myname) rule, do

bazel build //my/package:myname.par

The .par file is created alongside the python stub and .runfiles directories that py_binary() creates, but is independent of them. It can be copied to other directories or machines, and executed directly without needing the .runfiles directory. The body of the .par file contains all the srcs, deps, and data files listed.


  • C extension modules in ‘deps’ is not yet supported
  • Automatic re-extraction of ‘.runfiles’ is not yet supported
  • Does not include a copy of the Python interpreter (‘hermetic .par’)


Given a BUILD file with the following:

load("@subpar//:subpar.bzl", "par_binary")

    name = 'foo',
    srcs = ['', ''],
    deps = ['//baz:some_py_lib'],
    data = ['quux.dat'],

Run the following build command:

bazel build //package:foo.par

This results in the following files being created by bazel build:


The .par file can be copied, moved, or renamed, and still run like a compiled executable file:

$ scp bazel-bin/package/foo.par my-other-machine:foo.par
$ ssh my-other-machine ./foo.par

System Requirements

  • Python Versions: CPython versions 2.7.6+
  • Operating Systems: Debian-derived Linux, including Ubuntu and Goobuntu.


This is not an official Google product, it is just code that happens to be owned by Google.