Code Monkey home page Code Monkey logo

caput's Introduction

Caput

Easy file metadata.

Store metadata in a special YAML configuration header for text files, or a sidecar "shadow" configuration file for binary files.

Caput: n. Latin for "head" or "top". Root of many English words, such as "captain", "capital", and "decapitate".

Install

Caput is available from PyPI:

pip install caput

Usage

Say that you're building a static site generator. You can add a metadata header to any textfile. The first three bytes must be ---\n. In index.md:

---
title: My Site
author: Me
featured_image: /images/my-header.jpg
---
# Welcome to my site!

Read the metadata header:

>>> import caput

>>> caput.read_config('./index.md', defaults={'markup': 'markdown'})
{'markup': 'markdown',
 'title': 'My Site',
 'author': 'Me',
 'featured_image': '/images/my-header.jpg'}

Read the file contents:

>>> caput.read_contents('./index.md')
'# Welcome to my site!\n'

You can add metadata to binary files with a "shadow" header. For your featured image, add a .yml file with the same base name, e.g. for ./images/my-header.jpg you would add ./images/my-header.yml:

title: My Site Header
credit: Me

Read the metadata header:

>>> caput.read_config('./images/my-header.jpg')
{'title': 'My Site Header', 'credit': 'Me')

Read the file contents:

>>> caput.read_contents('./images/my-header.jpg', encoding=None)
b'...binary data...'

caput's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.