Skip to main content

mgnolia

Declarative filesystem structure and content validation for Python.

Define the expected layout of a directory using Dir and File nodes, optionally attach content validation rules, then call validate_all() to check a real directory against your schema. All errors are collected and returned as typed objects—nothing raises.

Installation

pip:

pip install mgnolia

uv:

uv add mgnolia

Quick Start

from mgnolia import Dir, File, Schema

# Define expected structure
schema = Schema(
    children=[
        Dir(
            path="data",
            description="Data directory",
            children=[
                File(path="input.csv"),
                File(path="output.json"),
            ],
        ),
        File(path="config.yaml"),
    ]
)

# Validate a directory
ok = schema.validate_all("/path/to/project")

if not ok:
    for error in schema.errors:
        print(error)
else:
    print("All checks passed!")

Content Rules

Attach validation rules to files to check their contents:

from mgnolia import File
from mgnolia.content import FileNotEmptyRule, CSVSchemaRule
from pydantic import BaseModel

class UserRow(BaseModel):
    id: int
    name: str
    email: str

File(
    path="users.csv",
    content_rules=[
        FileNotEmptyRule(),
        CSVSchemaRule(schema=UserRow),
    ],
)

Built-in rules:

  • FileNotEmptyRule() — fails if file is empty
  • CSVSchemaRule(schema=PydanticModel) — validates CSV against a Pydantic model using pandera

Error Types

When validation fails, schema.errors contains typed error objects:

  • Structure errors: FileMissingError, DirectoryMissingError, MinMatchError, MaxMatchError
  • Content errors: FileEmptyError, ContentSchemaError

All inherit from ValidationError and have .path and .node attributes. Use str(error) to get a formatted message.

Pattern Matching

Dir and File paths support glob patterns to match multiple files or directories:

File(path="*.log", min_matches=1)  # At least one .log file
Dir(path="test_*", max_matches=5)  # At most 5 test_* directories

License

MIT

Download files

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

Source Distribution

mgnolia-0.3.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

mgnolia-0.3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file mgnolia-0.3.0.tar.gz.

File metadata

  • Download URL: mgnolia-0.3.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mgnolia-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a129849fc36d00527973077dbefe20af802cd36fc6893c235aa09f604a9c5560
MD5 517a85d8207b9aa3e2eed08b1064e106
BLAKE2b-256 72851e2220b77b39def52f21814a07bf322fb7496e23395c8de5d52d43de66e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgnolia-0.3.0.tar.gz:

Publisher: release.yml on EBI-Metagenomics/mgnolia

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

File details

Details for the file mgnolia-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mgnolia-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mgnolia-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c88389e756acb7731d3792ea5dcab4873697a9f7ca9bab359399de6a031ef2e1
MD5 b96292ae4cf8caa50b5fe2aaf1e6661d
BLAKE2b-256 4e1fde5bdf7db5f5b11f81666f0a5278e167411ff91ddc97daefbc0d666a4407

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgnolia-0.3.0-py3-none-any.whl:

Publisher: release.yml on EBI-Metagenomics/mgnolia

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

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.0 This release

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