This release is a pre-release and may not be stable for production use.
The CAP Validator
The Python module for ensuring the validity of CAP alerts.
Features
- Schema Validation: Ensure your CAP XML file follows the CAP v1.2 standard.
- Digital Signature Validation: Verify that the CAP XML file comes from a legitimate source and has not been tampered with.
Note: Currently, only certificates issued by a trused certificate authority (CA) are supported. This means signatures with a self-signed certificate will not pass the validation.
Getting Started
1. Installation
pip install capvalidator
2A. Using the API
We can perform a total validation of the CAP XML file using validate_cap_message(cap, strict).
cap: The CAP alert XML byte string.strict: Whether or not signature validation is enforced. Defaults toTrue.
from capvalidator import validate_cap_message
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
# Perform the validation
result = validate_cap_message(cap, strict=True)
# Check the result
passed = result.passed
msg = result.msg
if not passed:
# Logic for handling invalid CAP file
# Logic for handling valid CAP file
Or, alternatively, we can perform a more refined validation using check_schema(cap) and/or check_signature(cap):
from capvalidator import check_schema, check_signature
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
# Validate the schema
schema_result = check_schema(cap)
# Check the results
passed = schema_result.passed
msg = schema_result.msg
if not passed:
# Logic for handling invalid CAP file
# Validate the signature
signature_result = check_signature(cap)
# Check the results
passed = signature_result.passed
msg = signature_result.msg
if not passed:
# Logic for handling invalid CAP file
# Logic for handling valid CAP file
There is also a date extractor get_dates(cap) which you may find useful:
from capvalidator import get_dates
# Read the CAP XML file as a byte string
with open(<cap-file-directory>, "rb") as f:
cap = f.read()
dts = get_dates(cap)
sent_date = dts.sent
effective_date = dts.effective
onset_date = dts.onset
expiry_date = dts.expiry
2B. Using the CLI
We can perform a total validation of the CAP XML file:
capvalidator validate <cap-file-directory>
By default this includes schema and signature validation.
To manually enable/disable enforcement of a valid XML signature, we can use the --strict or --no-strict arguments respectively:
capvalidator validate --strict <cap_file-directory>
capvalidator validate --no-strict <cap_file-directory>
Or, alternatively, for more refined validations we can use the --type argument:
capvalidator validate --type schema <cap-file-directory>
capvalidator validate --type signature <cap-file-directory>
Bugs and Issues
All bugs, enhancements and issues are managed on GitHub.
Contact
Metadata
Release files for capvalidator 0.1.0.dev4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| capvalidator-0.1.0.dev4.tar.gz | 17.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| capvalidator-0.1.0.dev4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.8 kB
Release files / capvalidator-0.1.0.dev4.tar.gz
| Download URL | capvalidator-0.1.0.dev4.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab9b7f1b7d49611412ac67510de5684dcbb2c566b091cf6a8ed2efdc585d9cac
|
|
BLAKE2b-256 checksum How to use checksums |
6ccf0a837823eefa82f137a4d3711bc34d39c792f5ad4033c946685eaefc4dbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|
Release files / capvalidator-0.1.0.dev4-py3-none-any.whl
| Download URL | capvalidator-0.1.0.dev4-py3-none-any.whl |
|---|---|
| Size | 15.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac803b68402dd8a58793172c62cf76812c43a2b44597e00e9e2088f239c9b580
|
|
BLAKE2b-256 checksum How to use checksums |
e9f71638ef7c6e1016945efd0c570dbb4ae5cf62ec818f1299ae084b2ed7d443
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.5
|