All Projects → eyeseast → Python Frontmatter

eyeseast / Python Frontmatter

Licence: mit
Parse and manage posts with YAML (or other) frontmatter

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Python Frontmatter

Gh Actions Yaml Generator
Ghygen is a GitHub Actions configurator for your Laravel Application.
Stars: ✭ 142 (-15.98%)
Mutual labels:  yaml
Dhallj
Dhall for Java
Stars: ✭ 154 (-8.88%)
Mutual labels:  yaml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-2.37%)
Mutual labels:  yaml
Serverless Ide Vscode
Serverless IDE: Enhanced support for AWS SAM and CloudFormation in VS Code
Stars: ✭ 145 (-14.2%)
Mutual labels:  yaml
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (-10.65%)
Mutual labels:  yaml
Yaml Multiline
Find the right syntax for your YAML multiline strings
Stars: ✭ 154 (-8.88%)
Mutual labels:  yaml
Cfgdiff
diff(1) all your configs
Stars: ✭ 138 (-18.34%)
Mutual labels:  yaml
Rcc
RCC is a set of tooling that allows you to create, manage, and distribute Python-based self-contained automation packages - or 'robots' as we call them.
Stars: ✭ 168 (-0.59%)
Mutual labels:  yaml
Jenkins Job Wrecker
convert Jenkins job XML to JJB YAML
Stars: ✭ 152 (-10.06%)
Mutual labels:  yaml
Terrible
An Ansible playbook that apply the principle of the Infrastructure as Code on a QEMU/KVM environment.
Stars: ✭ 161 (-4.73%)
Mutual labels:  yaml
Mortar
The manifest shooter for Kubernetes
Stars: ✭ 147 (-13.02%)
Mutual labels:  yaml
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (-11.24%)
Mutual labels:  yaml
Feedparser
feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
Stars: ✭ 156 (-7.69%)
Mutual labels:  yaml
Funzzy
Yet another fancy watcher. (Rust)
Stars: ✭ 142 (-15.98%)
Mutual labels:  yaml
Js Yaml Front Matter
Parses yaml or json from the beginning of a string or file
Stars: ✭ 165 (-2.37%)
Mutual labels:  yaml
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-15.98%)
Mutual labels:  yaml
Juju
Universal Operator Lifecycle Manager (OLM) for Kubernetes operators, and operators for traditional Linux and Windows apps, with declarative integration between operators for automated microservice integration.
Stars: ✭ 1,942 (+1049.11%)
Mutual labels:  yaml
Related
Nested Object Models in Python with dictionary, YAML, and JSON transformation support
Stars: ✭ 169 (+0%)
Mutual labels:  yaml
Models
WordPress plugin to create custom post types and taxonomies using JSON, YAML or PHP files
Stars: ✭ 167 (-1.18%)
Mutual labels:  yaml
K8ssandra
K8ssandra is an open-source distribution of Apache Cassandra for Kubernetes including API services and operational tooling.
Stars: ✭ 155 (-8.28%)
Mutual labels:  yaml

Python Frontmatter

Jekyll-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 (or JSON, TOML or other) front matter.

Tests PyPI

Documentation

Install:

pip install python-frontmatter

Usage:

>>> import frontmatter

Load a post from a filename:

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

Or a file (or file-like object):

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

Or load from text:

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

Access content:

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

# this works, too
>>> print(post)
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:

>>> sorted(post.keys())
['layout', 'title']

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

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

>>> with open('tests/yaml/hello-world.txt') 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.

Or write to a file (or file-like object):

>>> from io import BytesIO
>>> f = BytesIO()
>>> frontmatter.dump(post, f)
>>> print(f.getvalue().decode('utf-8')) # doctest: +NORMALIZE_WHITESPACE
---
excerpt: tl;dr
layout: post
title: Hello, world!
---
Well, hello there, world.

For more examples, see files in the tests/ directory. Each sample file has a corresponding .result.json file showing the expected parsed output. See also the examples/ directory, which covers more ways to customize input and output.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].