Skip to main content

A YAML-like data serialization language, and library.

Project description

FlatMatter

A YAML-like data serialization language with support for functions.

Example FlatMatter:

title: "My Blog"
last_updated: (get-content "posts") / (limit 1) / (get "publised_at") / (date "YYYY-mm-dd")
posts: "posts" / get-content

FlatMatter aims to be more-or-less syntactically compatible with YAML for the simple reason of not needing new editor plugins to have syntax highlighting, but it differs in that there is no indentation, but instead dots to indicate hierarchy, like site.title which would result in a site object that contains the title key.

FlatMatter also supports functions, allowing you to build your own data DSL, and functions can also be piped with the forward slash / character, meaning that the result of the left operation will be passed as the first argument of the next function, and so on, to produce an end result.

Install

pip install flatmatter

Usage

The most basic usage looks like this:

from flatmatter import FlatMatter

config = FlatMatter("title: \"My blog\"").to_dict()

However, you most likely want to use it with functions. Those you have to create yourself. An example function looks like this:

from flatmatter import Function, fn

@fn('my-function')
class MyFunction(Function):
  def compute(self, *args: list[Any]) -> Any:
    # do something with args here and return the desired result.

A FlatMatter function has to extend the Function base class, and has to use the fn decorator to name the function so that FlatMatter would know what to look for to find the function class. And like I mentioned before, a thing to keep in mind is that if the function is piped, its first arg will be the result of the previous operation.

Once you have your functions, simply pass them to FlatMatter like this:

from flatmatter import FlatMatter

config = FlatMatter("...", [
  MyFunction,
  MyOtherFunction,
  etc,
])

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

flatmatter-0.3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

flatmatter-0.3.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flatmatter-0.3.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for flatmatter-0.3.0.tar.gz
Algorithm Hash digest
SHA256 430aec8061591d0c4058d5a907cb2e464fae8b3e2f60af8ab4aad9149c95f201
MD5 404c29ab2fd496821019d8c838b04936
BLAKE2b-256 ddca2b27c4aec325285669f8877d22968f745a90a2e00b3e481ccbb6b7d808d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flatmatter-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for flatmatter-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c7573dedc23d82e6dd2aaa687d42ed96d70ea49c140276b3be26033a3897ad
MD5 c73ac9cd400d4c0b0bdaa4107ecb6949
BLAKE2b-256 9b8f364893cc98dd1d86dec29af4004ed4dc007ea13e6eed3e478e22edaea79a

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