Skip to main content

A data model linter

Project description


AstraLint

AstraLint is a Python linter for Space Physics data files, validating conformance to standards such as ISTP and PDS4.

๐Ÿš€ Try it online โ€” no installation required!

Overview

AstraLint validates data files against conformance suites using a codec-agnostic architecture:

  1. Codecs transform file formats (e.g., CDF) into a common abstract representation ( File)
  2. Suites define collections of validation rules (e.g., ISTP, PDS4)
  3. Rules check specific requirements, defined either in Python or YAML

Usage

# Lint a file against the default ISTP suite
astralint lint myfile.cdf

# Lint against a specific suite
astralint lint myfile.cdf --suite PDS4

# Select specific rules to run filtering by reference ID or name, regex supported
astralint lint myfile.cdf --suite ISTP --select "ISTP-MD-003" --select ".*GlobalAttributes"

# Ignore specific rules by reference ID or name, regex supported
astralint lint myfile.cdf --suite ISTP --ignore "ISTP-MD-00[0-9]" --ignore "MandatoryGlobalAttributes"

# List available suites
astralint list-suites

Architecture

flowchart TD
    subgraph Input["๐Ÿ“ฅ Input"]
        A[๐Ÿ“„ Data File]
    end
    
    subgraph Codecs["๐Ÿ”Œ Codecs (pluggable)"]
        B1[CDF Codec]
        B2[NetCDF Codec]
        B3[... more]
    end
    
    subgraph Core["โš™๏ธ Core"]
        C[๐Ÿ“ฆ Abstract File Model]
        D[๐Ÿ“‹ Conformance Suite]
        E[โœ… Rules & Assertions]
    end
    
    subgraph Suites["๐Ÿ“š Suites (pluggable)"]
        S1[ISTP]
        S2[PDS4]
        S3[... more]
    end
    
    subgraph Reports["๐Ÿ“Š Reports (pluggable)"]
        R1[Console]
        R2[JSON]
        R3[... more]
    end
    
    A --> B1 & B2 & B3
    B1 & B2 & B3 --> C
    C --> D
    S1 & S2 & S3 -.->|loads| D
    D --> E
    E --> R1 & R2 & R3
    
    style C fill:#fff3e0
    style Core fill:#f5f5f5,stroke:#999
    style Codecs fill:#e3f2fd,stroke:#1976d2
    style Suites fill:#fce4ec,stroke:#c2185b
    style Reports fill:#e8f5e9,stroke:#388e3c

File Model

The abstract File model is the core data structure that all codecs produce. Rules and assertions operate on this unified representation:

File
โ”œโ”€โ”€ compression: str                     # e.g., "gzip", "none"
โ”œโ”€โ”€ attributes: {name โ†’ Attribute}       # Global metadata
โ”‚   โ”œโ”€โ”€ "Project"      โ†’ Attribute
โ”‚   โ”œโ”€โ”€ "PI_name"      โ†’ Attribute
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ variables: {name โ†’ Variable}         # Data variables
    โ”œโ”€โ”€ "Epoch" โ†’ Variable
    โ”‚   โ”œโ”€โ”€ name: str                    # "Epoch"
    โ”‚   โ”œโ”€โ”€ shape: [int]                 # e.g., [1440]
    โ”‚   โ”œโ”€โ”€ attributes: {name โ†’ Attribute}
    โ”‚   โ”‚   โ”œโ”€โ”€ "CATDESC"  โ†’ Attribute
    โ”‚   โ”‚   โ”œโ”€โ”€ "FILLVAL"  โ†’ Attribute
    โ”‚   โ”‚   โ””โ”€โ”€ ...
    โ”‚   โ””โ”€โ”€ config: VariableBits
    โ”‚       โ”œโ”€โ”€ compression: str         # "gzip", "none"
    โ”‚       โ”œโ”€โ”€ data_type: DataType      # TT2000, FLOAT64, ...
    โ”‚       โ””โ”€โ”€ record_variance: bool
    โ”œโ”€โ”€ "Temperature" โ†’ Variable
    โ””โ”€โ”€ ...

Attribute
โ”œโ”€โ”€ name: str
โ””โ”€โ”€ data_type: DataType

DataType = CHAR | UINT8 | UINT16 | UINT32 | UINT64
         | INT8 | INT16 | INT32 | INT64
         | FLOAT32 | FLOAT64
         | TT2000 | CDFEPOCH | CDFEPOCH16

Path Navigation

Rules use /-separated paths with regex support to navigate the model:

Path Example Description
attributes Global attributes dictionary
attributes/Project Specific global attribute
variables All variables dictionary
variables/Epoch Specific variable
variables/.*/attributes Attributes of all variables
variables/Epoch/config/data_type Data type of a specific variable

Defining Rules in YAML

Rules can be defined declaratively in YAML files. Example from MandatoryAttributes.yaml:

name: MandatoryGlobalAttributes
description: "All mandatory global attributes must be present"
url: "https://..."
reference: "ISTP-MD-003"
severity: ERROR
suite: ISTP

assertions:
  - path: "attributes"
    check: contains_keys
    keys:
      - Data_type
      - Logical_source
      - PI_name
    message: "Missing mandatory global attribute: {key}"

  - path: "variables/.*/attributes"
    check: contains_keys
    keys: [ CATDESC, FIELDNAM, FILLVAL ]
    message: "Variable missing required attribute: {key}"

Available Assertion Types

Check Description
contains_keys Verifies an object contains required keys
matches Validates a string matches a regex pattern
is_type Checks a value has the expected data type

Supported File Formats

Format Extension Library
CDF .cdf pycdfpp

Available Conformance Suites (WIP/Demo)

Extending AstraLint

Adding a New Codec

Create a new codec in src/astralint/codecs/:

from astralint.base import Codec, File, classproperty


class MyCodec(Codec):
    @classproperty
    def supported_extensions(cls) -> list[str]:
        return ["ext"]

    @staticmethod
    def load(path: str) -> File:
        # Transform your file format into the abstract File model
        ...

Adding a New Assertion Type

Create a new assertion in src/astralint/base/yaml_rules/assertions/:

from typing import Literal, Any
from .base import BaseAssertion, resolve_path, ValidationResult, File


class MyAssertion(BaseAssertion):
    check: Literal["my_check"] = "my_check"

    # Add custom fields as needed, they will be populated from the YAML rule definition
    # e.g., expected_value: Any

    def single_assertion(self, file: File, path: str, value: Any) -> ValidationResult:
        # Implement your validation logic here, this method will be called for each path/value pair that matches the base assertion's path pattern
        # path is the resolved path in the File model, value is the value at that path
        ...

Project Docs

For how to install uv and Python, see installation.md.

For development workflows, see development.md.

For instructions on publishing to PyPI, see publishing.md.


This project was built from simple-modern-uv.

Project details


Download files

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

Source Distribution

astralint-0.1.3.tar.gz (672.0 kB view details)

Uploaded Source

Built Distribution

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

astralint-0.1.3-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file astralint-0.1.3.tar.gz.

File metadata

  • Download URL: astralint-0.1.3.tar.gz
  • Upload date:
  • Size: 672.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for astralint-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f29e24aa5cd72e02fac0777a377035e1f2e17c24970650c50dac3df3b9fce4f5
MD5 f4494d68ec5e39cf56aa5e9113bb45b5
BLAKE2b-256 a3e9efbbc7d9f733ca3b7386fc9e3b6dd91d8cfcfba352b0bb0d920cedcc2d7f

See more details on using hashes here.

File details

Details for the file astralint-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: astralint-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for astralint-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d56967ed93fe090d91d642e2e75fcbcd84ac8124ebfb0da9e2a12db6ffe4cf83
MD5 1d3e0175512b81d7f821d36c6c8a5a07
BLAKE2b-256 3f4418f0b68f8ab971ea5ef914a74a36557f31affe9d39dba9576d0d04e6443d

See more details on using hashes here.

Supported by

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