Skip to main content

A YAML-like data serialization language, and library.

Project description

FlatMatter

Coverage

A YAML-like data serialization language with support for functions. FlatMatter is considered feature-complete and is intentionally kept simple. Bug fixes and performance improvements are still made, of course.

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.9.1.tar.gz (8.2 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.9.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flatmatter-0.9.1.tar.gz
Algorithm Hash digest
SHA256 1ac0d949a593282fa52e4449ac1a5078a29720bbedd6664d0a517f8a8570e75a
MD5 4251c961c8b41e129bfd7a4951483f0c
BLAKE2b-256 584d18513c9293c702566b122c7aadaa1cb2fe499349ee0d19828592c66135ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: flatmatter-0.9.1-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.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d09942e66a23242219e1869bb3cf8a0f24f7048678690b158ee60fa9c9cad052
MD5 ca19c96131832130e21b7f8a82750940
BLAKE2b-256 fd5ac40e640fefb9471b8668ad0c9f869a2deb28b08e1ee9b2b495ebda7abd23

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