API Documentation

class fptokens.Token(name, escape='$')[source]

Token object for use in Filename.

Parameters:
  • name (str) – Token name
  • escape (str) – Escape character, default: $
name

Return the token name.

Returns:Token name
Return type:str
token

Return the full token including the escape characters either side.

Returns:Token
Return type:str
class fptokens.TokenError(message)[source]

Exception indicating an error related to Tokens, inherits from ValueError.

class fptokens.Filename(root, folders=[], base=[], separator='_', extension='jpg', escape='$')[source]

Filenames with support for tokens.

Parameters:
  • root (str) – Root location
  • folders (list of str) – Folder names, attribute supports tokens
  • base (list of str) – Basename of the file, attribute supports tokens
  • separator (str) – Separator for basename elements
  • extension (str) – Filename extension
  • escape (str) – Escape character for tokens, default: $
abspath

Return the filename’s full absolute path.

Returns:Absolute path
Return type:Path
basename

Return the filename’s basename.

Returns:Basename
Return type:str
dirname

Return the filename’s location.

Returns:Dirname
Return type:str
make()[source]

Create the filename’s location if it does not exist.

parse()[source]

Parse the filename’s folders and base attributes, detect components that match the token pattern and replace these with Token objects.

resolve(**kwargs)[source]

Given a set of **kwargs, yield all possible permutations for the data set provided. Raise TokenError if Filename does not haven tokens or the data provided does not match the tokens.

Params **kwargs:
 Permutation data
root

Return the filename’s root location.

Returns:Root location
Return type:Path
tokens

Return a list of all tokens in folders and base.

Returns:List of tokens
Return type:list