Skip to main content

Bicep RPC Client for Python

An independent Python client for programmatically interacting with the Bicep CLI over JSON-RPC.

Getting started

Install the package

python -m pip install anthonycmartin-bicep-rpc-client==0.1.7

The distribution is named anthonycmartin-bicep-rpc-client; import its public API from anthonycmartin.bicep_rpc_client.

Initialize the client

BicepClientFactory.initialize() downloads and caches the requested Bicep CLI version, starts bicep jsonrpc --stdio, and returns a client. Use the client as a context manager so the Bicep process is always terminated.

from anthonycmartin.bicep_rpc_client import BicepClientFactory

with BicepClientFactory().initialize() as client:
    print(f"Bicep CLI version: {client.get_version()}")

With no configuration, the factory resolves and caches the latest Bicep CLI under ~/.bicep/bin.

Pin a specific Bicep version

Set bicep_version without a leading v. Versioned CLIs are cached separately.

from anthonycmartin.bicep_rpc_client import BicepClientConfiguration, BicepClientFactory

client = BicepClientFactory().initialize(
    BicepClientConfiguration(bicep_version="0.46.1")
)

Use an existing Bicep installation

Set existing_cli_path to skip downloading the CLI. This takes precedence over bicep_version and cache_root.

client = BicepClientFactory().initialize(
    BicepClientConfiguration(existing_cli_path="/usr/local/bin/bicep")
)

Use a custom cache directory

client = BicepClientFactory().initialize(
    BicepClientConfiguration(
        bicep_version="0.46.1",
        cache_root="/var/cache/bicep",
    )
)

BicepClientConfiguration accepts bicep_version, existing_cli_path, and cache_root; every field is optional and paths may be strings or pathlib.Path values.

Available operations

All operations communicate synchronously with one Bicep CLI process. Relative request paths are resolved to absolute paths before they are sent. Bicep compilation failures are returned in typed response diagnostics; transport failures raise standard Python exceptions and JSON-RPC failures raise RpcError.

compile

compile() compiles a .bicep file into an ARM template JSON string.

from anthonycmartin.bicep_rpc_client import CompileRequest

result = client.compile(CompileRequest("./main.bicep"))
if result.success:
    print(result.contents)
else:
    print(result.diagnostics)

CompileRequest contains path. CompileResponse contains success, diagnostics, and contents; contents is None when the CLI does not return compiled output.

compile_params

compile_params() compiles a .bicepparam file into ARM deployment parameters and accepts JSON-serializable parameter overrides.

from anthonycmartin.bicep_rpc_client import CompileParamsRequest

result = client.compile_params(
    CompileParamsRequest(
        "./main.bicepparam",
        parameter_overrides={
            "environment": "test",
            "instanceCount": 2,
        },
    )
)
if result.success:
    print(result.parameters)
    print(result.template)
    print(result.template_spec_id)

CompileParamsRequest contains path and parameter_overrides. CompileParamsResponse contains success, diagnostics, parameters, template, and template_spec_id. The three content fields may be None; template_spec_id is populated when the parameters file references a template spec.

format

format() applies the standard Bicep formatter and returns the formatted source. It requires Bicep CLI 0.37.1 or later and does not write the file.

from pathlib import Path

from anthonycmartin.bicep_rpc_client import FormatRequest

result = client.format(FormatRequest("./main.bicep"))
Path("./main.bicep").write_text(result.contents, encoding="utf-8")

FormatRequest contains path. FormatResponse contains contents.

get_metadata

get_metadata() returns the parameters, outputs, exports, and file-level metadata declared by a Bicep file.

from anthonycmartin.bicep_rpc_client import GetMetadataRequest

result = client.get_metadata(GetMetadataRequest("./main.bicep"))
for parameter in result.parameters:
    print(f"parameter {parameter['name']}")
for output in result.outputs:
    print(f"output {output['name']}")
for exported in result.exports:
    print(f"export {exported['name']}")
for item in result.metadata:
    print(f"metadata {item['name']}")

GetMetadataRequest contains path. GetMetadataResponse exposes parameters, outputs, exports, and metadata as tuples of JSON-shaped dictionaries so fields added by future Bicep versions remain available.

get_file_references

get_file_references() returns every file referenced by a Bicep file, including modules, loaded files, and the entry point.

from anthonycmartin.bicep_rpc_client import GetFileReferencesRequest

result = client.get_file_references(GetFileReferencesRequest("./main.bicep"))
for file_path in result.file_paths:
    print(file_path)

GetFileReferencesRequest contains path. GetFileReferencesResponse contains the file_paths tuple.

get_deployment_graph

get_deployment_graph() returns resource nodes and dependency edges for visualization or graph analysis.

from anthonycmartin.bicep_rpc_client import GetDeploymentGraphRequest

result = client.get_deployment_graph(GetDeploymentGraphRequest("./main.bicep"))
for node in result.nodes:
    print(f"node {node['name']} ({node['type']})")
for edge in result.edges:
    print(f"{edge['source']} -> {edge['target']}")

GetDeploymentGraphRequest contains path. GetDeploymentGraphResponse exposes nodes and edges as tuples of JSON-shaped dictionaries.

get_snapshot

get_snapshot() evaluates a .bicepparam file using an Azure deployment context and returns a serialized deployment snapshot. It requires Bicep CLI 0.36.1 or later but does not deploy resources or require Azure credentials.

from anthonycmartin.bicep_rpc_client import (
    GetSnapshotRequest,
    SnapshotExternalInput,
    SnapshotMetadata,
)

with BicepClientFactory().initialize(
    BicepClientConfiguration(bicep_version="0.46.1")
) as client:
    result = client.get_snapshot(
        GetSnapshotRequest(
            "./main.bicepparam",
            metadata=SnapshotMetadata(
                tenant_id="ddbe463a-0554-485d-b589-0b17d60cd38b",
                subscription_id="28c9069e-23e8-47d2-b640-00d2e0f09616",
                resource_group="my-resource-group",
                location="eastus",
                deployment_name="my-deployment",
            ),
            external_inputs=(
                SnapshotExternalInput(
                    kind="sys.envVar",
                    config="BUILD_ID",
                    value="1234",
                ),
            ),
        )
    )
    print(result.snapshot)

SnapshotMetadata accepts optional tenant_id, subscription_id, resource_group, location, and deployment_name values. SnapshotExternalInput contains kind, value, and optional config. GetSnapshotRequest contains path, metadata, and the external_inputs tuple. GetSnapshotResponse contains the JSON snapshot in snapshot.

The development checkout adds optional management_group_id (unreleased), requiring Bicep CLI 0.47.16+. Older CLIs raise RuntimeError rather than silently ignoring it; whitespace-only values raise ValueError. Context is offline evaluation data, and deployment_name can influence offline results.

with BicepClientFactory().initialize(
    BicepClientConfiguration(bicep_version="0.47.16")
) as client:
    result = client.get_snapshot(GetSnapshotRequest(
        "./management-group.bicepparam",
        metadata=SnapshotMetadata(
            management_group_id="example-platform",
            location="eastus",
            deployment_name="offline-test",
        ),
    ))
    print(result.snapshot)

Use the shared management-group fixture. The response remains serialized JSON; generic resource and JSON traversal helpers belong to the testing framework. Context management still deterministically closes the stdio process.

get_version

get_version() returns the connected Bicep CLI version. The first result is cached for the lifetime of the client.

version = client.get_version()
print(version)

Client lifecycle

BicepClient owns the Bicep subprocess. Prefer a with block, or call close() explicitly. close() first asks the process to terminate, waits up to five seconds, and then kills it if necessary. Calling close() after the process exits has no effect.

client = BicepClientFactory().initialize(
    BicepClientConfiguration(bicep_version="0.46.1")
)
try:
    result = client.compile(CompileRequest("./main.bicep"))
finally:
    client.close()

BicepClient(executable) is also public for callers that already own Bicep installation and want to start the process directly. BicepClientFactory.initialize() is preferred because it locates or installs the CLI and verifies that the process responds to get_version() before returning.

Error handling

JSON-RPC server errors raise RpcError, a RuntimeError subclass with code, message, and data attributes.

from anthonycmartin.bicep_rpc_client import RpcError

try:
    result = client.compile(CompileRequest("./main.bicep"))
except RpcError as error:
    print(f"Bicep RPC error {error.code}: {error.message}")
    print(error.data)

Unsupported operation versions raise RuntimeError. A closed JSON-RPC output stream raises EOFError; download, process, serialization, and file errors retain their standard Python exception types.

Automatic downloads support Windows, Linux, and macOS on x64 and Arm64.

Public API summary

API Purpose
BicepClientConfiguration, BicepClientFactory.initialize() Select, cache, and start a Bicep CLI.
BicepClient, BicepClient.close() Own a JSON-RPC connection and Bicep process.
CompileRequest, CompileResponse, BicepClient.compile() Compile a .bicep file.
CompileParamsRequest, CompileParamsResponse, BicepClient.compile_params() Compile a .bicepparam file with optional overrides.
FormatRequest, FormatResponse, BicepClient.format() Format Bicep source.
GetMetadataRequest, GetMetadataResponse, BicepClient.get_metadata() Read declarations and metadata.
GetFileReferencesRequest, GetFileReferencesResponse, BicepClient.get_file_references() List referenced files.
GetDeploymentGraphRequest, GetDeploymentGraphResponse, BicepClient.get_deployment_graph() Read resource graph nodes and edges.
GetSnapshotRequest, SnapshotMetadata, SnapshotExternalInput, GetSnapshotResponse, BicepClient.get_snapshot() Evaluate a deployment snapshot.
BicepClient.get_version() Read the connected CLI version.
RpcError Inspect a JSON-RPC server error.

All request, response, metadata, external-input, and configuration models are immutable slotted dataclasses.

This package is independent and non-official. Its API may change between releases.

Metadata

Release files for anthonycmartin-bicep-rpc-client 0.1.7

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

Source distribution (sdist)

Source distribution for anthonycmartin-bicep-rpc-client 0.1.7
File Size Uploaded Provenance Actions
anthonycmartin_bicep_rpc_client-0.1.7.tar.gz 13.0 kB With provenance Details for anthonycmartin_bicep_rpc_client-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for anthonycmartin-bicep-rpc-client 0.1.7
File Interpreter ABI Platform Actions
anthonycmartin_bicep_rpc_client-0.1.7-py3-none-any.whl Python 3 none any Details for anthonycmartin_bicep_rpc_client-0.1.7-py3-none-any.whl

Total release size: 22.6 kB

Release files / anthonycmartin_bicep_rpc_client-0.1.7.tar.gz

Download URL anthonycmartin_bicep_rpc_client-0.1.7.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c33c17cb3e4a6d740147d0f5e826c25a8930f865c14452f1b96b7dcee92c8ca0
BLAKE2b-256 checksum
How to use checksums
fb3545f32e2dc97c313ff1fc6a592b16e9cabc77b16310bb74d159ccf726a622
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 7, 2026.

Transparency log

Release files / anthonycmartin_bicep_rpc_client-0.1.7-py3-none-any.whl

Download URL anthonycmartin_bicep_rpc_client-0.1.7-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1224631fe3f1157cc72873b57a06e42ab8fb8b9e011eceede9d07b09cc8e4a7
BLAKE2b-256 checksum
How to use checksums
8dfbc2148ced51ce9925b47882c1b1c5442396bc3f77d405a070234f75804ad0
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 7, 2026.

Transparency log

Security for anthonycmartin-bicep-rpc-client 0.1.7

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for anthonycmartin_bicep_rpc_client-0.1.7.tar.gz

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

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