Skip to main content

Manage key/value metadata in file names.

Project description

fna

Introduction

The problem

Many types of files have associated metadata, e.g. title and creators, but there is no universal way to record this. Some file formats contain metadata fields, but not all do. Some file systems provide for metadata tagging, but most don't. Both are externally invisible, which makes them easy to accidentally lose. There are external tagging tools, but the association between a file and its external records is likewise easy to lose.

This solution

Some metadata is placed in the file name itself, where it won't be accidentally separated from the file. In many cases, this metadata includes some kind of unique identifier (e.g. ISBN for books, DOI for papers) that can be used to find additional information.

This tool, fna (for ‘File Name Attributes’) helps automate managing key-value pairs in file names.

For certain keys, the values can have associated semantics beyond their text. For example, ISBNs can be normalized to ISBN-13 and have their checksums corrected.

Installation

The easiest (?) way to install fna is from PyPi using pip. Depending on your system, one of the following may work:

  • pip install fnattr
  • pip install --user fnattr
  • pipx install fnattr
  • python -m pip install fnattr

Usage

By default, fna follows a subcommand familiar from tools like git, except that it's typical to chain multiple subcommands in a single invocation.

Run fna help to get a list of subcommands, and fna help ‹subcommand› for information on a particular subcommand.

See doc/fna.md for more information.

(More complicated operations are possible using Python expressions rather than the subcommands, but this is not yet stable or documented.)

Examples

This example uses two subcommands, file, which takes a file name as argument, and add, which takes key and value as arguments:

$ fna file '/tmp/My Book.pdf' add isbn 1234567890
/tmp/My Book [isbn=9781234567897].pdf

If no subcommand causes output or side effects, fna prints the resulting file name or string.

Rename a file (three subcommands):

$ fna \
  file '/tmp/My Book.pdf' \
  add isbn 1234567890 \
  rename

Get a JSON representation (four subcommands):

$ fna \
  file '/tmp/My Book.pdf' \
  add isbn 1234567890 \
  json \
  encode
{"title": ["My Book"], "isbn": ["9781234567897"]}

Configuration

Unless otherwise directed by a command line option, fna tries to read fnattr/vlju.toml or fnattr/fna.toml from XDG locations (e.g. $HOME/.config/). The former is shared by all tools using the Vlju library, while the latter applies only to the fna command.

This file can define keys and classes associated with web sites, mapping between a compact ID to a URL. The distribution file config/vlju.toml contains some examples.

See doc/configuration.md for more information.

Implementation

The current public home for fna is https://codeberg.org/datatravelandexperiments/fna

fna is written in Python primarily because (in the original version) the standard library shlex module provided input file tokenization ‘for free’ (sometimes free is expensive). It was originally written in Python 2 circa 2010, and substantially revised in 2023.

fna aims for 100% unit test coverage (outside of extra/) and full type annotation (outside of unit tests). It is currently tested on Python versions 3.11 through 3.14.

src/util

Code that does not depend on vlju, and could be useful in unrelated projects.

src/vlju

vlju.Vlju (pronounced ‘value’) is the base data type for attribute values. Every Vlju has a string representation. Many subclasses have additional internal structure; e.g. the ISBN subclass handles 10- and 13-digit ISBNs including their checksums.

src/vlju can depend on src/util.

src/vljumap

vljumap.VljuMap is a key-value store (multimap) associating string keys with (one or more) Vlju values.

vljumap.enc contains code to convert VljuMap to and from string representations.

src/vljumap can depend on src/vlju and src/util.

src/vljum

Code implementing the subcommands.

src/vljum can depend on src/vljumap, src/vlju and src/util.

src/fna

The command line tool fna.

TODO

  • Better error handling. Too much still just raises exceptions.
  • Document operation with -[EFx].

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

fnattr-0.2.10.tar.gz (396.6 kB view details)

Uploaded Source

Built Distribution

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

fnattr-0.2.10-py3-none-any.whl (403.6 kB view details)

Uploaded Python 3

File details

Details for the file fnattr-0.2.10.tar.gz.

File metadata

  • Download URL: fnattr-0.2.10.tar.gz
  • Upload date:
  • Size: 396.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for fnattr-0.2.10.tar.gz
Algorithm Hash digest
SHA256 8c73926fc346ba481be0923e185e107b3daa16c7dec1dee087fca290353955f8
MD5 70513aab194e87a30e6b6ae7da52a1b0
BLAKE2b-256 3b1781a28b7dd65162d068511bba1a280567e296602826ede477f78ccfc8715b

See more details on using hashes here.

File details

Details for the file fnattr-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: fnattr-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 403.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for fnattr-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 39053df22dc5a16e81fad2c4e08a483af2abb5f85aca47d4f0a3d8d7b7e48f21
MD5 f9f8d4586e03f3c50fae3526589f73f5
BLAKE2b-256 bd000743592dd91d6ee0ac5a6b2533e2c0d0455898763e5524839dcafbd02c29

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