Skip to main content

No project description provided

Project description

sysappend

This appends every folder in your repository to the sys.path variable, so Python is able to import any folder.

If you use this package, you don't need to pollute your project with __init__.py files, and you will unlock relative imports (both parent and child folders) from anywhere, without all the fuss. You will get correctly working debug, test and deploy features without going mad. At the same time, you get correct type-hinting, syntax highlighting, and module highlights.

This package does require you to add a short one-liner to the top of all your Python files (it doesn't need to be all files -- but it's convenient and can be enforced with CI/CD, GitHub actions or simply added via a quick copy-paste).

In my opinion, this solves the super-nasty import and relative package management in an developer-friendly way which basic Python fails to deliver.

How to use it

  1. pip install sysappend
  2. Add an if True: import sysappend; sysappend.all() statement at the top of every python file in your repo. (It doesn't need to be every file, but it's just easier for convenience, and the function caches results avoiding redundant computation, so it doesn't slow the code down).

Recommended folder referencing when importing

You should always try to reference the folders in the same way.
For example, use one (or few) agreed-upon primary source code folder from which to reference the sub-directories and stick to that convention.

E.g., if your directory looks like the below, you could pick src to be the primary source code folder:

sample_project/
    src/
        sub_folder_1/
            utils.py
        sub_folder_2/
            models.py
    app.py

So, when you write imports, they should start from the primary src folder.

E.g., in your app.py file, you should do:

from src.sub_folder_1.utils import somefunction

and you should do the same thing in models.py:

from src.sub_folder_1.utils import somefunction

Do not use a sub_folder as a starting name for an import, i.e., do not do from sub_folder_1.utils import somefunction. Although it will may still work in most cases, it may fail when you do type comparisons or deserialization, as Python looks at the import path to compare/deserialize types.

Quality of life setting for editors like VSCode

If you're using an editor like VSCode, you may want to add the main primary source code folder(s) to your settings.json file, like:

    "python.autoComplete.extraPaths": [
        "./src",
    ]

This will help the autocomplete to reference the folders always starting from src, in the same way as explained above -- i.e., you won't get automatic completion that attempt to do imports from sub folders.

Installation

pip install sysappend

Example usage

Place this line at the top of every Python file:

if True: import sysappend; sysappend.all()

Note: the if True: is optional, but it's useful to avoid linters/automated procedures to move this line from the top position.

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

sysappend-1.6.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

sysappend-1.6.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file sysappend-1.6.2.tar.gz.

File metadata

  • Download URL: sysappend-1.6.2.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for sysappend-1.6.2.tar.gz
Algorithm Hash digest
SHA256 215d78b80e4db913a0a5dc7c21e7879d73a3254865c6345317ffb86c87ac4ae0
MD5 0c33d53b102be8c33416f8d53b2fa967
BLAKE2b-256 c32c5c8abf5bbba1b2f2aebb93b5b3b647f35e0411fa974225718c8df29b46a9

See more details on using hashes here.

File details

Details for the file sysappend-1.6.2-py3-none-any.whl.

File metadata

  • Download URL: sysappend-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for sysappend-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ef75547e1b4299c8a9bdcd157b43517866364c435f557e5a4c924dfc5aa4ae5
MD5 f422b86f1fd6b11b0cdd9d3580836694
BLAKE2b-256 bfa393b07b9d6636bf04b8cf6465f7737c3aa3095a94fd5d5ee44d449a494bd6

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