Skip to main content

Enhanced package importer that handles complex Python import patterns

Project description

smooth_import

PyPI version Python versions License: MIT

An enhanced package importer for Python that handles complex import patterns including:

  • ✅ Relative imports without __init__.py
  • ✅ Mixed package and standalone structures
  • ✅ Dynamic import resolution
  • ✅ Automatic import rewriting
  • ✅ Circular dependency handling

Installation

pip install smooth_import

Quick Start

from smooth_import import resolve_import

# Resolve an import from a specific file
my_function = resolve_import("path/to/my_module.py", "my_function")

Features

  • Smart Import Resolution: Automatically handles complex import patterns
  • No init.py Required: Works with modern Python projects that don't use __init__.py files
  • Mixed Package Support: Handles both package and standalone module structures
  • Dynamic Import Rewriting: Automatically rewrites imports to work correctly
  • Circular Dependency Handling: Safely handles circular import scenarios

Usage Examples

Basic Usage

from smooth_import import resolve_import, PackageImporter

# Using the convenience function
my_function = resolve_import("path/to/my_module.py", "my_function")

# Using the PackageImporter class directly
importer = PackageImporter(verbose=True)
result = importer.resolve_import("path/to/my_module.py", "my_function")

Advanced Usage

from smooth_import import PackageImporter

# Create an importer with custom settings
importer = PackageImporter(verbose=False)

# Resolve imports from complex project structures
try:
    my_class = importer.resolve_import("src/myproject/modules/utils.py", "MyClass")
    print(f"Successfully imported: {my_class}")
except ImportError as e:
    print(f"Import failed: {e}")

Development

This project uses modern Python packaging with pyproject.toml. The redundant setup.py has been removed for cleaner project structure.

Building and Publishing

  1. Install build tools:

    pip install build twine
    
  2. Build the package:

    python -m build
    
  3. Test the build locally:

    pip install dist/smooth_import-1.0.0.tar.gz
    
  4. Upload to PyPI (replace with your PyPI credentials):

    twine upload dist/*
    

Development Setup

# Clone the repository
git clone https://github.com/sawradip/smooth_import.git
cd smooth_import

# Install in development mode
pip install -e .

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black .

# Lint code
flake8

Requirements

  • Python 3.7+
  • No external dependencies (uses only standard library)

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues or have questions:

  1. Check the documentation
  2. Open an issue
  3. Review the examples directory

Changelog

See CHANGELOG.md for a list of changes and version history.

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

smooth_import-1.0.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

smooth_import-1.0.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file smooth_import-1.0.1.tar.gz.

File metadata

  • Download URL: smooth_import-1.0.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for smooth_import-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2a76448652f2e2f2ae1e83a8dc231c416cb0e62abd77f3e01e5a3adebd6f5bbd
MD5 a344a15360f46a7d4d68d8ba17fc56a3
BLAKE2b-256 f11c032e9c26085402eae20c619e1fad8ba2e667c84bd7597ef8ae92926ba2ca

See more details on using hashes here.

File details

Details for the file smooth_import-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: smooth_import-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for smooth_import-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fd455232c6f6c31982e9ec8df5db25984821fde91b12e534bc626d42a7fb6e0
MD5 9c0093332832c8d6deb52c53ffe8408b
BLAKE2b-256 ab0b1e1edf69e0ca38bab1b1a5e88c4179024d9c4fee6922ad730806c93c0a1e

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