Skip to main content

A python package for handling path aliases.

Project description


Build Status

A python package for handling path aliases.

Path aliases can be loaded directly from YAML files:

    alias: SUBDIR
      alias: SUBDIR_2

file.txt: { alias: [FILE, ALTERNATE_ALIAS] }

  extra_keys: are ignored
  alias: 2ndDir

    can/be/addressed/with: { alias: A_PATH_INDEPENDANT_ALIAS }

Resolving this with pathaliases.resolve_yaml_to_path_strings("aliases.yml") returns a dictionary:

    "SUBDIR": "dir/subdir/",
    "SUBDIR_2": "dir/subdir/some/other/dir/"
    "FILE": "file.txt",
    "ALTERNATE_ALIAS": "file.txt",
    "2ndDir": "dir2/",
    "A_PATH_INDEPENDENT_ALIAS": "some/very/long/path/into/a/deep/file/hierarchy/can/be/addressed/with"

Which can be used to make codebases independent from paths:

# Before
subdir = "dir/subdir/"
subdir_2 = os.path.join(subdir, subdir_2)

# After: *where* the dirs are is configurable
aliases = pathaliases.resolve_yaml_to_path_strings("aliases.yml")
subdir = aliases["SUBDIR"]
subdir_2 = aliases["SUBDIR_2"]

pathaliases is designed to be:

  • Simple - It just concatenates all the keys that lead up to an alias.
  • Readable - Developers and admins should be able to edit paths easily.
  • Standard - It uses standard file formats and conventions, making it easy to port to other languages.


Clone the repo:

$ git clone
$ python install


Resolve aliases directly from a YAML file:

import pathaliases

aliases = pathaliases.resolve_yaml_to_path_strings("aliases.yml")

print(aliases["SUBDIR"])  # echoes: "dir/subdir/"

Resolve aliases from a dict:

import pathaliases

aliases_dict = {
    "dir/": {
        "subdir/": {"alias": "SUBDIR"}

aliases = pathaliases.resolve_path_strings(aliases_dict)
print(aliases["SUBDIR"])  # echoes: "dir/subdir/"

Substituting Variables

Alias files can also contain variables, templated with ${VARNAME}:

    alias: ${key}

pathaliases allows you to pass in an environment when evaluating paths:

env = {
  "var": "bar",
  "key": "some_alias"

aliases =  pathaliases.resolve_yaml_to_path_strings("aliases.yml", env=env)

aliases == {
  "some_alias": "foo/bar/",

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pathaliases, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size pathaliases-0.0.3-py3-none-any.whl (5.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pathaliases-0.0.3.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page