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-2.0.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: sysappend-2.0.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for sysappend-2.0.0.tar.gz
Algorithm Hash digest
SHA256 32b9c9fbff0855ca6d7be5b38bbcad29f35c3f2b69630f93fb98a4fc9dd4dec9
MD5 30803a6a4aa345144e4ab7397ef21599
BLAKE2b-256 cd69d00e2121ac23d2cf9e720c60849c9c3335bc79bac7a88901d7b264203533

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for sysappend-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f07c085da8a568f5c75ac4eca8a8e201f087f23454f2be8d2ce1ecf88ae8564
MD5 f32e2143fe1035d399c23bf396b106b0
BLAKE2b-256 22293be3c088aab59b7d666d934f835a27681e3b62545948771a34884371169b

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