Skip to main content

OSCAL Python Library

A Python library for working with OSCAL (Open Security Controls Assessment Language) content. Provides classes to load, validate, convert, and manipulate OSCAL XML, JSON, and YAML documents for all published OSCAL versions and models.


Features

  • All OSCAL models: Catalog, Profile, Mapping, Component Definition, SSP, Assessment Plan, Assessment Results, POA&M
  • All OSCAL formats: XML, JSON, and YAML — load any, save to any
  • All published OSCAL versions: pre-populated support database covers every NIST release; update to learn new versions as they are published
  • Pure-Python format conversion: no external XSLT processor required
  • Metaschema-based validation: structure, data-type, allowed-value, and cardinality checks against the NIST metaschema
  • Import resolution: automatically loads referenced catalogs, profiles, and other documents; surfaces structured failure details when imports cannot be resolved
  • Path-based querying: XPath-inspired syntax for navigating OSCAL content using either XML element names or JSON key names
  • Air-gapped operation: the bundled support database enables full offline use; update from an internet-connected machine and transfer the database file

Installation

pip install oscal

Latest unreleased development version:

pip install git+https://github.com/brian-ruf/oscal-class.git@develop#egg=oscal

Quick Start

Create a new catalog

from oscal import Catalog

catalog = Catalog.new(
    title="My Catalog",
    version="1.0.0",
    published="2026-03-02T00:00:00Z",
)

catalog.create_control_group(
    parent_id="", id="ac", title="Access Control",
    props=[{"name": "label", "value": "AC"},
           {"name": "sort-id", "value": "001"}],
)
catalog.create_control(
    parent_id="ac", id="ac-1",
    title="Access Control Policy and Procedures",
    props=[{"name": "label", "value": "AC-1"},
           {"name": "sort-id", "value": "001-001"}],
    statements=["Develop, document, and disseminate an access control policy."],
)

# Save to XML, JSON, and YAML in one step each
catalog.dump("catalog.json", format="json", pretty_print=True)
catalog.dump("catalog.xml",  format="xml",  pretty_print=True)
catalog.dump("catalog.yaml", format="yaml")

Load and convert existing content

from oscal import Catalog

# Load from any supported format
catalog = Catalog.load("./catalog.xml")

if catalog:
    print(f"{catalog.title} ({catalog.oscal_version})")
    catalog.dump("catalog.json", format="json", pretty_print=True)
else:
    print(f"Load failed: {catalog.content_state.name}")

Load in-memory content

from oscal import OSCAL

xml_str = """<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="http://csrc.nist.gov/ns/oscal/1.0" uuid="8e38fb28-...">
  <metadata>
    <title>My Catalog</title>
    <version>DRAFT</version>
    <oscal-version>1.1.3</oscal-version>
  </metadata>
</catalog>"""

doc = OSCAL.loads(xml_str)
print(doc.model, doc.title)   # catalog   My Catalog

Acquire from a URI

from oscal import OSCAL

doc = OSCAL.acquire("https://raw.githubusercontent.com/.../catalog.json")

# Fallback list — first successful source wins
doc = OSCAL.acquire([
    "https://primary.example.com/catalog.json",
    "./local-fallback/catalog.json",
])

Query content

# XML element name syntax
ctrl  = catalog.query_one('//control[@id="ac-2"]')
title = catalog.query_one('/*/metadata/title')

# JSON key name syntax
ctrl  = catalog.json_query_one('//controls[id="ac-2"]')
stmts = catalog.json_query('//parts[name="statement"]')

Model Classes

Class OSCAL model
Catalog catalog
Profile profile
Mapping mapping-collection
ComponentDefinition component-definition
SSP system-security-plan
AssessmentPlan assessment-plan
AssessmentResults assessment-results
POAM plan-of-action-and-milestones

Use the base OSCAL class when the model is not known in advance.


Documentation

Document Contents
Getting Started Installation, loading patterns, saving, and a walkthrough example
OSCAL Class API Complete class reference: factory methods, states, querying, mutation, import handling
Querying Content Full path syntax for query() and json_query()
Import Resolution How imports are resolved, failure codes, and retry API
Format Converters OSCALConverter and markup conversion internals
Support Module Support database configuration, updates, and API
Logging Enabling Loguru logging

Designed for Air-Gapped Environments

The OSCALSupport class manages a local SQLite database of NIST-published metaschema and support files for every OSCAL version. The database ships pre-populated, enabling full offline operation from the moment you install the library.

To learn a newly published OSCAL version:

from oscal.oscal_support import get_support

support = get_support()
support.update()           # fetch any new NIST releases

Run update() on an internet-connected machine, then copy the updated support/oscal_support.db into the air-gapped environment.


Feedback and Contributions

Please submit bug reports and feature requests as GitHub issues. Bug fixes and backward-compatible contributions are welcome. Please open an issue before starting work on any breaking changes.


Use of AI in This Library

No portion of this library was "vibe coded."

Early versions were written entirely without AI tools. Claude / Claude Code and GitHub Copilot have since been used in a manner similar to pair programming:

  • Options analysis when planning approaches
  • Alignment with Pythonic best practices
  • Targeted code reviews and linter resolution
  • Debugging and testing support
  • Drafting individual functions and methods (reviewed and tested before merge)
  • Drafting documentation and unit tests

Ruf Risk Logo

Cybersecurity Consulting
https://RufRisk.com
https://www.linkedin.com/company/rufrisk/

Brian J. Ruf, CISSP, CCSP, PMP
OSCAL Co-Creator, Independent Consultant
https://www.linkedin.com/in/brianruf/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oscal-3.0.0.tar.gz (13.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oscal-3.0.0-py3-none-any.whl (13.7 MB view details)

Uploaded Python 3

File details

Details for the file oscal-3.0.0.tar.gz.

File metadata

  • Download URL: oscal-3.0.0.tar.gz
  • Upload date:
  • Size: 13.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oscal-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c85427a9004942b697cadcf5ca125afad7a0aae49431543d2d3a6341fed99ee8
MD5 a0d0c29bd7f0d1e5420255df4832a182
BLAKE2b-256 bfe9611a85d10e51e77d99a29dc77ccad265bcde5fefb47bc1d2f5850165f4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for oscal-3.0.0.tar.gz:

Publisher: publish.yml on brian-ruf/oscal-class

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oscal-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: oscal-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for oscal-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e76b953eefeed1cfa5d02e7ca5471660979c11f3a8c371122d937ca6267e3347
MD5 ef270edea15ab4c485e8359c05e23cda
BLAKE2b-256 8896f5ac7f83863ae6098eb36dd69dc7373d42e09f15f91e1ac2eb1bdf3b9d75

See more details on using hashes here.

Provenance

The following attestation bundles were made for oscal-3.0.0-py3-none-any.whl:

Publisher: publish.yml on brian-ruf/oscal-class

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.1.1

2 files

3.1.0

2 files

This release

3.0.0 This release

2 files

2.0.0

2 files

1.0.3

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page