Skip to main content

[Jekyll](http://jekyllrb.com/)-style YAML front matter offers a useful way to add arbitrary, structured metadata to text documents, regardless of type.

This is a small package to load and parse files (or just text) with YAML front matter.

Usage:

>>> import frontmatter

Load a post from a filename:

>>> post = frontmatter.load('tests/hello-world.markdown')

Or a file (or file-like object):

>>> with open('tests/hello-world.markdown') as f:
...     post = frontmatter.load(f)

Or load from text:

>>> with open('tests/hello-world.markdown') as f:
...     post = frontmatter.loads(f.read())

Access content:

>>> print post.content
Well, hello there, world.

Use metadata (metadata gets proxied as post keys):

>>> print post['title']
Hello, world!

Metadata is a dictionary, with some handy proxies:

>>> post.keys()
['layout', 'title']
>>> post['excerpt'] = 'tl;dr'
>>> post.metadata
{'excerpt': 'tl;dr', 'layout': 'post', 'title': 'Hello, world!'}

If you don’t need the whole post object, just parse:

>>> with open('tests/hello-world.markdown') as f:
...     metadata, content = frontmatter.parse(f.read())
>>> print metadata['title']
Hello, world!

Write back to plain text, too:

>>> print frontmatter.dumps(post) # doctest: +NORMALIZE_WHITESPACE
---
excerpt: tl;dr
layout: post
title: Hello, world!
---
Well, hello there, world.

Download files

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

Source Distribution

python-frontmatter-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file python-frontmatter-0.1.0.tar.gz.

File metadata

File hashes

Hashes for python-frontmatter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b71792883000c333dc6f67c1a7c960b6cf5d90681dab69edb045583f08e7dd98
MD5 ae1f27c9d35440c3b9fd0c29047beb0d
BLAKE2b-256 38e8602828bd1c7440bd36725a37f07f10a5279592d567bb5e114a7020d810ba

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 Sentry Error logging StatusPage Status page