{"id":18084496,"url":"https://github.com/eyeseast/python-frontmatter","last_synced_at":"2025-05-16T01:05:01.855Z","repository":{"id":20754400,"uuid":"24038919","full_name":"eyeseast/python-frontmatter","owner":"eyeseast","description":"Parse and manage posts with YAML (or other) frontmatter","archived":false,"fork":false,"pushed_at":"2024-01-16T18:49:16.000Z","size":149,"stargazers_count":360,"open_issues_count":14,"forks_count":43,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-08T21:36:22.741Z","etag":null,"topics":["frontmatter","python","yaml"],"latest_commit_sha":null,"homepage":"http://python-frontmatter.rtfd.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eyeseast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"eyeseast"}},"created_at":"2014-09-15T01:51:06.000Z","updated_at":"2025-05-07T05:38:20.000Z","dependencies_parsed_at":"2023-11-11T19:26:36.140Z","dependency_job_id":"9d694d5c-f27d-4202-9a36-0bf9725e3608","html_url":"https://github.com/eyeseast/python-frontmatter","commit_stats":{"total_commits":121,"total_committers":13,"mean_commits":9.307692307692308,"dds":"0.17355371900826444","last_synced_commit":"3910ac705cabdd6e2cd5844ffed60798f09a0f6b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyeseast%2Fpython-frontmatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyeseast%2Fpython-frontmatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyeseast%2Fpython-frontmatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyeseast%2Fpython-frontmatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eyeseast","download_url":"https://codeload.github.com/eyeseast/python-frontmatter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["frontmatter","python","yaml"],"created_at":"2024-10-31T15:07:00.232Z","updated_at":"2025-05-16T01:04:56.818Z","avatar_url":"https://github.com/eyeseast.png","language":"Python","readme":"# Python Frontmatter\n\n[Jekyll](http://jekyllrb.com/)-style YAML front matter offers a useful way to add arbitrary, structured metadata to text documents, regardless of type.\n\nThis is a small package to load and parse files (or just text) with YAML (or JSON, TOML or other) front matter.\n\n[![Tests](https://github.com/eyeseast/python-frontmatter/workflows/Test/badge.svg)](https://github.com/eyeseast/python-frontmatter/actions?query=workflow%3ATest)\n[![PyPI](https://img.shields.io/pypi/v/python-frontmatter.svg)](https://pypi.org/project/python-frontmatter/)\n\n**[Documentation](https://python-frontmatter.readthedocs.io/en/latest/)**\n\n## Install:\n\n    pip install python-frontmatter\n\n## Usage:\n\n```python\n\u003e\u003e\u003e import frontmatter\n\n```\n\nLoad a post from a filename:\n\n```python\n\u003e\u003e\u003e post = frontmatter.load('tests/yaml/hello-world.txt')\n\n```\n\nOr a file (or file-like object):\n\n```python\n\u003e\u003e\u003e with open('tests/yaml/hello-world.txt') as f:\n...     post = frontmatter.load(f)\n\n```\n\nOr load from text:\n\n```python\n\u003e\u003e\u003e with open('tests/yaml/hello-world.txt') as f:\n...     post = frontmatter.loads(f.read())\n\n```\n\nIf the file has a [Byte-Order Mark](https://en.wikipedia.org/wiki/Byte_order_mark) (BOM), strip it off first. An easy way to do this is by using the [`utf-8-sig`](https://docs.python.org/3/library/codecs.html?highlight=utf%208%20sig#module-encodings.utf_8_sig) encoding:\n\n```python\n\u003e\u003e\u003e with open('tests/yaml/hello-world.txt', encoding=\"utf-8-sig\") as f:\n...     post = frontmatter.load(f)\n\n```\n\nAccess content:\n\n```python\n\u003e\u003e\u003e print(post.content)\nWell, hello there, world.\n\n# this works, too\n\u003e\u003e\u003e print(post)\nWell, hello there, world.\n\n```\n\nUse metadata (metadata gets proxied as post keys):\n\n```python\n\u003e\u003e\u003e print(post['title'])\nHello, world!\n\n```\n\nMetadata is a dictionary, with some handy proxies:\n\n```python\n\u003e\u003e\u003e sorted(post.keys())\n['layout', 'title']\n\n\u003e\u003e\u003e from pprint import pprint\n\u003e\u003e\u003e post['excerpt'] = 'tl;dr'\n\u003e\u003e\u003e pprint(post.metadata)\n{'excerpt': 'tl;dr', 'layout': 'post', 'title': 'Hello, world!'}\n\n```\n\nIf you don't need the whole post object, just parse:\n\n```python\n\u003e\u003e\u003e with open('tests/yaml/hello-world.txt') as f:\n...     metadata, content = frontmatter.parse(f.read())\n\u003e\u003e\u003e print(metadata['title'])\nHello, world!\n\n```\n\nWrite back to plain text, too:\n\n```python\n\u003e\u003e\u003e print(frontmatter.dumps(post)) # doctest: +NORMALIZE_WHITESPACE\n---\nexcerpt: tl;dr\nlayout: post\ntitle: Hello, world!\n---\nWell, hello there, world.\n\n```\n\nOr write to a file (or file-like object):\n\n```python\n\u003e\u003e\u003e from io import BytesIO\n\u003e\u003e\u003e f = BytesIO()\n\u003e\u003e\u003e frontmatter.dump(post, f)\n\u003e\u003e\u003e print(f.getvalue().decode('utf-8')) # doctest: +NORMALIZE_WHITESPACE\n---\nexcerpt: tl;dr\nlayout: post\ntitle: Hello, world!\n---\nWell, hello there, world.\n\n```\n\nFor 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.\n","funding_links":["https://github.com/sponsors/eyeseast"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyeseast%2Fpython-frontmatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feyeseast%2Fpython-frontmatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyeseast%2Fpython-frontmatter/lists"}