Azurehound / Guides / Python

Azurehound and Python: Analysing Output and Python-Based Tooling

Is there an Azurehound Python version? Learn how Azurehound relates to Python, how to analyse its JSON output with Python, and which Python tools complement it.

Azurehound and Python: Analysing Output and Python-Based Tooling

Clearing Up a Common Question

"Azurehound Python" is a frequent search, and it usually comes from one of three assumptions: that Azurehound is written in Python, that there is a Python package to install with pip, or that Python is required to run it. None of these is the case. Azurehound is written in Go and ships as a compiled binary. You do not need Python installed, and there is no official pip install azurehound package.

That said, Python and Azurehound are excellent partners. Python is ideal for analysing Azurehound's JSON output, automating collections, feeding results into reporting pipelines and working alongside Python-based Azure tools. This guide explains those relationships and gives practical, working examples.

Why Azurehound Is Written in Go

SpecterOps chose Go for sound engineering reasons:

  • Single binary distribution. No interpreter, virtual environment or dependency resolution is needed on the collection machine.
  • Concurrency. Go's goroutines make it efficient to page through large Microsoft Graph result sets in parallel.
  • Cross-compilation. One codebase produces builds for Windows, Linux and macOS on multiple architectures.
  • Performance. Compiled code handles large tenants faster than an interpreted script.

For a collector that must run reliably on locked-down audit workstations, those properties matter more than the convenience of a scripting language.

Where Python Fits In

Python shines after collection. Common uses include:

  • Summarising what a collection contains before importing it into BloodHound.
  • Comparing two collections to find new users, applications or role assignments.
  • Extracting specific findings for reports or ticketing systems.
  • Orchestrating scheduled Azurehound runs and handling output files.
  • Querying BloodHound's API to automate attack-path checks.

Understanding the Output Structure

Azurehound writes a JSON document whose top-level data array contains one entry per collected item. Each entry carries a kind field describing its type, such as AZUser, AZGroup, AZApp or AZServicePrincipal, and a data field holding the object's properties or relationship details. Exact field names can change between versions, so always inspect a sample file before writing analysis code.

A quick way to explore the structure:

import json

with open("output.json", encoding="utf-8") as f:
    doc = json.load(f)

print(doc.keys())
print(len(doc["data"]))
print(json.dumps(doc["data"][0], indent=2)[:1500])

Example 1: Count Objects by Type

import json
from collections import Counter

with open("output.json", encoding="utf-8") as f:
    items = json.load(f)["data"]

kinds = Counter(item.get("kind") for item in items)
for kind, count in kinds.most_common():
    print(f"{kind:35} {count:>8}")

This produces an immediate inventory: how many users, groups, devices, applications, role assignments and resources the collection captured. Comparing these counts with figures from the Entra admin centre is a useful sanity check that the collection was complete.

Example 2: Compare Two Collections

Tracking change over time is one of the most valuable things you can do with Azurehound. A simple diff of object identifiers shows what appeared or disappeared:

import json

def ids_by_kind(path, kind):
    with open(path, encoding="utf-8") as f:
        items = json.load(f)["data"]
    out = set()
    for item in items:
        if item.get("kind") == kind:
            obj = item.get("data", {})
            ident = obj.get("id") or obj.get("objectId")
            if ident:
                out.add(ident)
    return out

old = ids_by_kind("contoso-2026-10.json", "AZServicePrincipal")
new = ids_by_kind("contoso-2026-11.json", "AZServicePrincipal")
print("New service principals:", len(new - old))
print("Removed service principals:", len(old - new))

New service principals deserve attention because they often carry application permissions that create fresh attack paths.

Example 3: Automate Collection With Python

Python's subprocess module makes it easy to orchestrate Azurehound, for example in a scheduled job:

import datetime, os, subprocess, sys

tenant = os.environ["AH_TENANT"]
app_id = os.environ["AH_APP_ID"]
cert = os.environ["AH_CERT"]
key = os.environ["AH_KEY"]
stamp = datetime.date.today().isoformat()
out = f"/secure/azurehound/{tenant}-{stamp}.json"

cmd = ["azurehound", "list", "-a", app_id, "--cert", cert, "--key", key,
       "--tenant", tenant, "-o", out, "--log-file", out.replace(".json", ".log")]
result = subprocess.run(cmd)
if result.returncode != 0:
    sys.exit("AzureHound collection failed")
os.chmod(out, 0o600)
print("Saved", out)

Reading credentials from environment variables, or better from a secrets manager, keeps them out of the script. Setting restrictive permissions on the output protects it immediately.

Example 4: Working With BloodHound's API

BloodHound Community Edition exposes an HTTP API. With Python's requests library and an API token generated in the BloodHound interface, you can automate uploads and run saved queries. Because the API evolves, consult the API documentation for your BloodHound version rather than relying on fixed endpoint paths. Teams commonly use this to upload each new Azurehound file automatically and then run a set of Cypher queries that count paths to Global Administrator, producing a single metric to track over time.

Python-Based Tools That Complement Azurehound

Several respected Azure security tools are written in Python:

ToolFocusRelationship to Azurehound
ROADtools (roadrecon)Entra ID reconnaissance into a local databaseAlternative view of directory data; can export to BloodHound through a plugin
ScoutSuiteMulti-cloud configuration auditingFinds misconfigurations rather than attack paths
ProwlerCloud security posture checksCompliance-oriented, complementary to path analysis
BloodHound CE Python collectorOn-premises Active DirectoryPairs with Azurehound for hybrid environments

Using Azurehound for attack-path data and a Python tool for configuration or reconnaissance detail gives a more complete assessment than either alone.

Handling Large Files in Python

Big tenants produce big JSON files, sometimes hundreds of megabytes. Loading them entirely with json.load may use several gigabytes of memory. For very large files, consider a streaming parser such as ijson, which processes items one at a time:

import ijson
from collections import Counter

counts = Counter()
with open("output.json", "rb") as f:
    for item in ijson.items(f, "data.item"):
        counts[item.get("kind")] += 1
print(counts.most_common(10))

Protecting Data in Python Workflows

When Python touches Azurehound output, the same care applies as anywhere else:

  • Keep analysis scripts and data in encrypted, access-controlled locations.
  • Avoid printing sensitive fields to logs that are shipped elsewhere.
  • Never commit output files or credentials to version control; add them to .gitignore.
  • Delete intermediate files such as CSV extracts when the engagement ends.

Exporting Findings to Spreadsheets and Reports

Many stakeholders never open BloodHound. They read spreadsheets, dashboards and written reports. Python makes it simple to convert Azurehound data into formats those audiences already use. The csv module in the standard library is enough for basic exports:

import csv, json

with open("output.json", encoding="utf-8") as f:
    items = json.load(f)["data"]

with open("service_principals.csv", "w", newline="", encoding="utf-8") as out:
    writer = csv.writer(out)
    writer.writerow(["displayName", "appId", "id"])
    for item in items:
        if item.get("kind") == "AZServicePrincipal":
            d = item.get("data", {})
            writer.writerow([d.get("displayName"), d.get("appId"), d.get("id")])

Field names depend on your Azurehound version, so inspect a sample record first and adjust the keys accordingly. For richer analysis, libraries such as pandas allow grouping, filtering and charting, though they add dependencies to your analysis environment.

Exports deserve the same protection as the original JSON. A spreadsheet of service principals and owners is still sensitive, and it is easier to forward accidentally. Label files clearly, store them with the rest of the engagement data and include them in your deletion schedule.

Keeping analysis reproducible

Store analysis scripts in version control, separately from data, and record which Azurehound version each script was written for. When the output format evolves, you can update the script once and rerun it across historical collections, producing consistent figures for trend reporting.

A Simple Python Health Check

Before importing any file, a ten-line Python check can confirm that the collection is complete: count objects by kind, verify that key types such as users, groups, service principals and subscriptions are present, and compare totals with the previous run. Large unexplained drops usually indicate a failed or truncated collection rather than a genuine change in the tenant.

Key Takeaways

  • Azurehound is written in Go; there is no official Python version or pip package.
  • Python is ideal for summarising, comparing and exporting Azurehound JSON output.
  • Inspect a sample record before writing scripts, because field names can change between versions.
  • Use streaming parsers such as ijson for very large collection files.
  • ROADtools, ScoutSuite and Prowler are Python tools that complement Azurehound well.
  • Protect exports and analysis files exactly as carefully as the original JSON output.

FAQs

No. Azurehound is written in Go and distributed as a compiled binary. There is no official Python package.
No. Azurehound runs on its own. Python is only useful for analysing output or automating workflows around it.
Yes. The standard json module works for most files, and streaming parsers such as ijson handle very large outputs efficiently.
ROADtools is the best-known Python tool for Entra ID reconnaissance. It collects similar directory data but uses a different analysis model.
Yes, through BloodHound's API with an API token. Check the API documentation for your BloodHound version.
Be cautious. Any package using that name is not an official SpecterOps release. Obtain Azurehound only from GitHub, Kali or Homebrew.

Conclusion

Azurehound is a Go program, not a Python one, and that design makes collection fast and dependable. Python, however, is the perfect companion: it turns raw Azurehound output into inventories, change reports and automated metrics, orchestrates scheduled collections and connects to complementary tools such as ROADtools. Use Azurehound to gather the graph and Python to put that graph to work.