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

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.

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

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.5
File Size Uploaded
anthonycmartin_bicep_rpc_client-0.1.5.tar.gz 12.1 kB Details

Built distribution (wheel)

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

Total release size: 21.3 kB

Release files / anthonycmartin_bicep_rpc_client-0.1.5.tar.gz

Download URL anthonycmartin_bicep_rpc_client-0.1.5.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ff30dbd338f0d21723dd39c6bbbf5fd609b0f8983abadddcdace695baa56911c
BLAKE2b-256 checksum
How to use checksums
92c6878e913350cf59859fff7b6bb2efed32ce9854cc96e1689fa26528cf79a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

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

Download URL anthonycmartin_bicep_rpc_client-0.1.5-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b4964ee0c5a733b223345dcb3573f4745d64a6c602a3b094ed645a99d010444
BLAKE2b-256 checksum
How to use checksums
ff2eddac41fbf396cca05cdea4ff6e7d21977c38c5c324cc27139a01bd145d51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.6

2 release files

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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