Skip to main content

Find a config file in XDG paths, home or calling package path

Project description

FindConfig

FindConfig is a Python package which implements the simple task of looking for a configuration file in a series of locations.

Usage

from findconfig import findconfig

config = findconfig("my.config.yaml")

The command above returns the Pathlib path of the first file found in the locations indicated below (in the order), which has the given filename, with or without a prepended dot (e.g. .my.config.yaml in the example above).

Config file locations

The locations which are searched are, in order of priority:

  • the directories indicated in the XDG specification:
    • XDG config home
    • XDG config dirs
  • the home directory of the user
  • the source code directory of the calling program:
    • the directory of the calling module
    • any ancestor directory, stopping at (and including) the first one which does not contain a __init__.py file
  • directories listed in the more_path keyword argument

Options

The following keyword options can be used:

more_path (list of strings or Path, default: []): directory names to be searched
  into, in the order, _after_ the default locations stated above

allow_dot (boolean, default: True): also look for the filename with a prepended
  dot, if the filename does not start with a dot

use_xdg (boolean, default: True): enable searching in the XDG specification paths
use_home (boolean, default: True): enable searching in the user home directory
use_src (boolean, default: True): enable searching in the source code directory
                              of the program
src_climb (int, default: 1): maximum number of ancestor directories to search
                             from the first directory without a __init__.py file
                             starting from the directory containing the calling
                             module

exception (boolean, default: False): raise an exception is the file is not found
                                     (default: return None and do not raise)

verbose (boolean, default: False): print the path of the found configuration
                                   file to the standard error

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

findconfig-1.2.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

findconfig-1.2.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file findconfig-1.2.2.tar.gz.

File metadata

  • Download URL: findconfig-1.2.2.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.7

File hashes

Hashes for findconfig-1.2.2.tar.gz
Algorithm Hash digest
SHA256 9fe0b5748b215082ba8e1861e9528e492884589912569b32221d6d57d015e123
MD5 2421303a038c2e09746fd540cd978e7f
BLAKE2b-256 a331163300a441446ab371c848182bab3b4830207498de5be9c522cfa10521d2

See more details on using hashes here.

File details

Details for the file findconfig-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: findconfig-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.7

File hashes

Hashes for findconfig-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05f501d9259776ce3697d1d6e7c62b3f37af971fb2eebd331eef1357c4f1ae2b
MD5 ca6da399e143b920964e8b53646e8c5c
BLAKE2b-256 a23ce36ed82478474a3c2606c6e1ba7cf2f60ad446cb37733dd8d2de6c0f43af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page