Skip to main content

Dorsal

A local-first file metadata generation and management toolkit.

PyPI version Python versions License Documentation
Tests codecov Mypy checked

Dorsal is an extensible, local-first framework and command line tool for generating, validating, and managing structured file metadata.

Dorsal provides configurable extraction and annotation pipelines for files.

Dorsal is...

  • Local First: Metadata extraction happens locally, not in the cloud. Use the CLI or python API to run the built-in extraction models or incorporate your own.
  • Strictly Validated: All annotations are automatically checked against strict JSON Schemas and Pydantic models, ensuring predictability and easy downstream integration.
  • Batteries Included: No file-type restrictions, and out-of-the-box support for core metadata extraction for many common file types including PDFs, Office documents, Media files and more.
  • Extensible: Support your own file types and metadata annotation needs. Integrate your own models easily.

Installation

Dorsal is available on PyPI as dorsalhub.

pip install dorsalhub

On Linux and macOS, Dorsal also needs the libmagic and mediainfo system libraries (e.g. apt install libmagic1 libmediainfo0v5 or brew install libmagic media-info).

Authentication

To sync metadata records with DorsalHub, authenticate with an API Key (generate one on your DorsalHub settings page).

dorsal auth login

Alternatively, set the DORSAL_API_KEY environment variable.


CLI Usage

1. Scan a File

Generate a metadata record for a file using the default extraction pipeline.

dorsal scan "docs/PDFSPEC.pdf"

Output:

PDFSPEC.pdf

File
  Path        docs/PDFSPEC.pdf
  Modified    2025-04-09 15:09:05
  Name        PDFSPEC.pdf
  Size        1 MiB
  Media type  application/pdf

PDF
  author         Tim Bienz, Richard Cohn, James R. Meehan
  title          Portable Document Format Reference Manual (v 1.2)
  creator        FrameMaker 5.1.1
  producer       Acrobat Distiller 3.0 for Power Macintosh
  subject        Description of the PDF file format
  keywords       Acrobat PDF
  version        1.2
  page_count     394
  creation_date  1996-11-12T03:08:43
  modified_date  1996-11-12T07:58:15

Add --deep to also compute the file's hashes.


2. Push Metadata

Sync the metadata record to DorsalHub. By default, this creates a private record visible only to you.

dorsal push "docs/PDFSPEC.pdf"

3. Run Annotation Models

Annotation Models are plug and play packages for Dorsal which perform file extraction, annotation or conversion.

Explore the models available on dorsalhub.com or follow a tutorial to build your own.

You can run and install models directly from the command line:

dorsal install dorsalhub/pdf-extractor

You can also export to any format supported by OATS Adapters:

$ dorsal run dorsalhub/whisper /home/video/test.mkv --export=srt
1
00:00:01,970 --> 00:00:05,970
You might be wondering how I ended up in this situation.

2
00:00:05,970 --> 00:00:08,970
Yeah that's me. A young subtitle.

3
00:00:08,970 --> 00:00:18,590
Little did I know what life had in store for me.


Outputs saved successfully:
  ↳ /home/user/sandbox/test.dorsal.json
  ↳ /home/user/sandbox/test.srt

4. Parse, Validate, and Export

Dorsal has two companion libraries to handle data structure and interoperability:

  • OATS (Open Annotation Task Schemas): Dorsal annotations are strictly validated against these versioned, source-agnostic JSON schemas (e.g., classification, document-extraction). This ensures predictable outputs.

  • OATS Adapters: A bundled utility that converts between strictly validated JSON records and standard file formats.

Example: Parse a standard file into a validated JSON record:

$ dorsal adapter parse OSR_uk_000_0020_8k.srt audio-transcription

Example: List available export formats for a schema:

$ dorsal adapter list document-extraction

Supported Export Formats

You can currently export validated records into the following formats:

Document Extraction (document-extraction):

  • Markdown (.md)
  • HTML (.html)
  • hOCR (.hocr.html)
  • TSV (.tsv)
  • Plain Text (.txt)

Audio Transcription (audio-transcription):

  • SRT (.srt)
  • WebVTT (.vtt)
  • Markdown (.md)
  • TSV (.tsv)
  • Plain Text (.txt)

Citation / Reference (dorsal/arxiv):

  • BibTeX (.bib)
  • CSL-JSON (.json)
  • RIS (.ris)
  • Markdown (.md)

Python API

The LocalFile class runs the extraction pipeline on a specific file path.

1. Access Extracted Data

from dorsal import LocalFile

# 1. Initialize (runs the pipeline)
lf = LocalFile("docs/PDFSPEC.pdf")

# 2. Access base attributes
print(f"Hash: {lf.hash}")
print(f"Type: {lf.media_type}")

# 3. Access format-specific attributes (if available)
if lf.pdf:
    print(f"Pages: {lf.pdf.page_count}")
    print(f"Title: {lf.pdf.title}")

2. Add Tags & Annotations

# Add a simple key-value tag
lf.add_tag(name="project_id", value=12345)

# Add a structured annotation (validates against the 'classification' schema)
lf.add_classification(labels=[{"label": "urgent", "score": 1.0}], vocabulary=["urgent", "review"])

# Sync the enriched record to DorsalHub (private by default; pass public=True to share it)
lf.push()

Custom Annotation Models

You can extend Dorsal by adding custom Annotation Models to the extraction pipeline. These are Python classes that define extraction logic and the output schema.

Example: A "Hello Word" Model

This toy model counts the top 5 words in a text file.

from collections import Counter
from dorsal import AnnotationModel
from dorsal.testing import run_model
from dorsal.file.helpers import build_generic_record


class HelloWord(AnnotationModel):
    def main(self):
        with open(self.file_path, "r") as f:
            words = f.read().split()

        data = {str(i + 1): v[0] for i, v in enumerate(Counter(words).most_common(5))}

        return build_generic_record(description="Top 5 most common words", data=data)


# Validate the model
results = run_model(annotation_model=HelloWord, file_path="./path/to/test/file.txt", schema_id="generic")

assert not results[0].error

You can add it to Dorsal's local file metadata extraction pipeline:

from dorsal.api import register_model
from helloword import HelloWord

# Add the model to your pipeline
register_model(annotation_model=HelloWord, schema_id="generic")

Now, each time you run dorsal scan or LocalFile(), this model will execute automatically.


Resources

License

Dorsal is open source and provided under the Apache 2.0 license.

Metadata

Release files for dorsalhub 0.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dorsalhub 0.13.0
File Size Uploaded Provenance Actions
dorsalhub-0.13.0.tar.gz 3.8 MB Without provenance Details for dorsalhub-0.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dorsalhub 0.13.0
File Interpreter ABI Platform Actions
dorsalhub-0.13.0-py3-none-any.whl Python 3 none any Details for dorsalhub-0.13.0-py3-none-any.whl

Total release size: 5.2 MB

Release files / dorsalhub-0.13.0.tar.gz

Download URL dorsalhub-0.13.0.tar.gz
Size 3.8 MB
Tags Source
SHA-256 checksum
How to use checksums
85037342c3d4475770bed7fde9ea0c593adf1fb73db50434f383c9198ea861af
BLAKE2b-256 checksum
How to use checksums
bf83cd4071151fdab59372e2a3c6bf3d4e4f25e1f614fbae3b50543d9a2d293f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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":null}

Release files / dorsalhub-0.13.0-py3-none-any.whl

Download URL dorsalhub-0.13.0-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
aa6cfa056d520aff14552fa57ab7f84b4ec08dd34b131347c19421ecefd65c69
BLAKE2b-256 checksum
How to use checksums
58f75463e577526063b4060f130b953970b32481c6bb3e50ff9ebabbdefc6662
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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":null}

Security for dorsalhub 0.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.13.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page