Skip to main content

A function to append all folders and subfolders of the root directory to the Python path.

Project description

pypathadd

pypathadd is a simple Python utility that appends all folders and subfolders of a specified root directory to the Python path. This functionality can simplify package imports, especially in larger projects with nested directories.

Features

  • Automatically adds all folders and subfolders in a specified root directory to the Python path.
  • Allows exclusion of specific folders (e.g., __pycache__) to keep the path clean.
  • Simple, flexible, and lightweight, making it easy to integrate into any project.

Installation

You can install pypathadd from PyPI:

pip install pypathadd

Usage

Here’s a quick example of how to use pypathadd to simplify your import paths.

Basic Example

from pypathadd import py_auto_append

# Automatically append folders from the root directory two levels up
py_auto_append(__file__, levels_up=2, verbose=True)

# You can now import modules from parent directories without adjusting sys.path manually
import your_module_in_parent_dir

Arguments

  • path_caller (str): Path of the calling module, typically file.
  • levels_up (int, optional): Number of levels to go up from the caller path to set the root directory. Defaults to 0.
  • rm_elems (List[str], optional): List of folder names (or substrings) to exclude from being added to the path. Defaults to ['pycache', '.', 'config', 'web'].
  • verbose (bool, optional): If True, prints each path added to the system path. Defaults to False.

Example with Custom Arguments

from pypathadd import py_auto_append

# Specify folders to exclude from path
py_auto_append(__file__, levels_up=1, rm_elems=['__pycache__', 'tests'], verbose=True)

Why use pypathadd?

In projects with deep folder structures, importing modules from different parts of the hierarchy can be cumbersome. pypathadd dynamically appends paths to sys.path, allowing for clean and organized imports across directories.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

pypathadd-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

pypathadd-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file pypathadd-0.1.0.tar.gz.

File metadata

  • Download URL: pypathadd-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for pypathadd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b91df84280236a7945da906a0aded51c34f6ce06a5922672f2f96a3702b79af
MD5 ac5b9adf7063470995aafde07e61300b
BLAKE2b-256 2920a97a2c81820e60f6177a8ceb5e8fa7117a9902124fb52fa16db34abfbc93

See more details on using hashes here.

File details

Details for the file pypathadd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypathadd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for pypathadd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 520fca8357665ab6086a3480aaa2086f4a7141eef831ebd0a5b2663c55ab308c
MD5 4c61e8ec8f414d3c76e1e04934aaf5ba
BLAKE2b-256 c46884468738fe937aff7b26bae6a8f3f93f8a9013866729fad1da034a09ccc5

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