Skip to main content

aimport

A minimal library for python: Adding support for smart imports with automatic path resolution.

Usage

import aimport

This automatically adds relevant directories to sys.path based on __aimport__ anchor files found in the directory tree.

Features

  • Smart path resolution: Automatically discovers project roots using __aimport__ anchor files
  • Anchor file content support: __aimport__ files can contain paths that will be used instead of the file location
  • Multiple paths support: NEW in v2.1.0: __aimport__ files can contain multiple paths, one per line
  • Fallback support: Falls back to __init__.py files when no __aimport__ files are found
  • Priority ordering: BREAKING CHANGE v2.0.0: New paths are now prepended to sys.path instead of appended, giving them higher import priority
  • Duplicate prevention: Avoids adding duplicate paths to sys.path
  • Automatic execution: Works immediately upon import

Breaking Changes in v2.0.0

⚠️ Import Priority Change: Starting with v2.0.0, discovered paths are prepended to sys.path instead of appended. This means modules in aimport-discovered directories will take precedence over existing sys.path entries. This change ensures that project-local modules are found before system or virtual environment modules.

New Features in v2.1.0

🎉 Multiple Paths Support: __aimport__ files can now contain multiple paths, one per line. This allows a single anchor file to reference multiple directories that should be added to the import path.

How It Works

  1. Anchor File Discovery: Searches upward from the starting directory for __aimport__ files
  2. Content Processing: If an __aimport__ file contains valid paths (one per line), those paths are used; otherwise the file's directory is used
  3. Multiple Path Support: Each line in an __aimport__ file is treated as a separate path - empty lines and whitespace-only lines are ignored
  4. Fallback Mechanism: If no __aimport__ files are found, falls back to searching for __init__.py files
  5. Path Priority: All discovered paths are added to the beginning of sys.path for higher import priority

Anchor File Format

__aimport__ files can contain:

  • Empty file: Uses the directory containing the file
  • Single path: Uses that path (absolute or relative)
  • Multiple paths: One path per line, uses all valid paths

Example __aimport__ file with multiple paths:

../lib
./vendor
/absolute/path/to/modules

Testing

The project includes comprehensive unit tests using pytest:

# Install development dependencies
uv sync --dev

# Run all tests
./test.sh

# Or run pytest directly
uv run pytest tests/ -v

Test Coverage

  • 23 comprehensive test cases
  • Full coverage of all functions and edge cases
  • Integration tests for complex directory structures
  • Behavior-focused testing (not implementation details)

Development

# Build distribution
python setup.py sdist

# Upload to PyPI
twine upload dist/*

Metadata

Release files for aimport 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aimport 2.1.0
File Size Uploaded Provenance
aimport-2.1.0.tar.gz 8.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aimport 2.1.0
File Interpreter ABI Platform
aimport-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / aimport-2.1.0.tar.gz

Download URL aimport-2.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a5f533c8c5d2be63422eba14ce34464d29da04dbd12577832755ed53b5b652c2
BLAKE2b-256 checksum
How to use checksums
9145813e977d996163db52775d15cb370aec8bc1ea0a3eb33f3967b5aeb4ccf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / aimport-2.1.0-py3-none-any.whl

Download URL aimport-2.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38ceb283bb2ced984a02ff428863e293416c03dea3429c08318d91e5c48bc6d2
BLAKE2b-256 checksum
How to use checksums
cb7e1ad43683dff19c8c42e1fa8eacef2afcf21e27bdd0c450651326ef4fbdc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for aimport 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page