Skip to main content

Tiny YAML-frontmatter parser/serializer/patcher for markdown documents. Mirrored API with the TypeScript sibling @fedoup/frontmatter so a vault of .md files round-trips byte-for-byte across languages.

Project description

fedoup-frontmatter

Tiny YAML-frontmatter parser/serializer/patcher for markdown documents. Sibling of the TypeScript package @fedoup/frontmatter — same API shape, same byte-stable round trip on canonical input, so a vault of .md files written by one side round-trips through the other.

pip install fedoup-frontmatter
from fedoup_frontmatter import parse, serialize, patch

raw = """---
title: Hello
status: draft
---

# Body content
"""

result = parse(raw)
result.frontmatter   # {'title': 'Hello', 'status': 'draft'}
result.body          # '# Body content\n'

# Round-trip is byte-stable for canonical input
serialize(frontmatter=result.frontmatter, body=result.body) == raw

# Patch a single field, leave the rest alone
patch(raw, {"status": "published"})

API

@dataclass
class ParseResult:
    frontmatter: dict[str, Any]
    body: str

def parse(raw: str) -> ParseResult: ...
def serialize(*, frontmatter: Mapping[str, Any], body: str) -> str: ...
def patch(raw: str, partial: Mapping[str, Any]) -> str: ...
  • parse — returns ParseResult(frontmatter={}, body=raw) if the document doesn't open with a --- line. A UTF-8 BOM is tolerated; CRLF endings are accepted but the body is not normalized.
  • serialize — empty frontmatter returns the body verbatim (no ---\n---\n no-op block). Key order is preserved from the input dict.
  • patch — merges partial into the existing frontmatter. Body and unaffected fields are preserved. To delete a key, parse → mutate the dict → serialize directly.

Power source

Uses PyYAML under the hood — full YAML support (scalars, sequences, mappings, anchors). The minimal regex parsers you see in many vault tools have edge cases this avoids; the cost is the PyYAML dependency.

Sibling: TypeScript

A matching JS/TS package at @fedoup/frontmatter exists. Same function names, same semantics. Test fixtures are mirrored between the two repos so behavior stays aligned.

License

MIT

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

fedoup_frontmatter-0.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

fedoup_frontmatter-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fedoup_frontmatter-0.1.0.tar.gz.

File metadata

  • Download URL: fedoup_frontmatter-0.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fedoup_frontmatter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c327487ee6805bbc60ca6efc4ae2c8579b6c65bb777b6d4e086fe50a93131849
MD5 9d30601e0a2ccc6866d40da9a265c944
BLAKE2b-256 abe8689ce1208d44601a338120906748fee892391cbd1ddc29b8f2dc43555244

See more details on using hashes here.

File details

Details for the file fedoup_frontmatter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fedoup_frontmatter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fedoup_frontmatter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a397fddf14781eceef34a8a3a5e8903d5fc1f74f843e0bbcf595c5c5ac979bfa
MD5 a300e6e561432c3e6ba852c977932ac6
BLAKE2b-256 b10a4715ca12b0de71f61aab549cca8f232b326df7340c323d84bf544bdf0104

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