Skip to content

ultralytics/autoimport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Ultralytics logo

⚡️ autoimport: Effortless Lazy Imports in Python

autoimport is a lightweight Python package that provides effortless lazy imports. By using the lazy context manager, modules are imported only when they are actually accessed, improving startup times and reducing initial memory footprint. Ideal for projects with heavy dependencies that are not always needed. The ultralytics-autoimport package is published on PyPI for easy installation.

autoimport CI Ultralytics Actions Discord Ultralytics Forums Ultralytics Reddit

🚀 Quick Start

Install the ultralytics-autoimport package from PyPI:

PyPI - Version Downloads PyPI - Python Version

pip install ultralytics-autoimport

Use the lazy context manager to defer imports:

import time

from autoimport import lazy

with lazy():
    t0 = time.perf_counter()
    import torch  # Import is deferred until first use

    print(f"Initial import time: {time.perf_counter() - t0:.3f}s")  # Example output: 0.000s

t1 = time.perf_counter()
torch.cuda.is_available()  # Package is actually loaded here
print(f"First use time: {time.perf_counter() - t1:.3f}s")  # Example output: 0.462s

🗂 Repository Structure

The repository is organized for clarity and ease of development:

  • autoimport/: Contains the source code of the autoimport package.
  • tests/: Unit tests to ensure code reliability.
  • pyproject.toml: Project configuration, including dependencies and packaging details.
  • .gitignore: Specifies files to be excluded from Git tracking.
  • LICENSE: The open-source license for the project (AGPL-3.0).
  • .github/workflows/: GitHub Actions workflows for CI/CD.
autoimport/
│
├── autoimport/
│   ├── __init__.py
│   └── ...
│
├── tests/
│   ├── __init__.py
│   ├── test_autoimport.py
│   └── ...
│
├── pyproject.toml
└── README.md

Source Code in src/autoimport/ Directory 📂

The src/autoimport/ directory contains the core Python code for the autoimport package.

Testing with the tests/ Directory 🧪

The tests/ directory includes tests to maintain code quality and prevent regressions.

➕ Starting a New Project

This repository can also serve as a template for new Python projects at Ultralytics.

To use it as a template:

  1. Create a New Repository: Use this as a template to generate a new repository.
  2. Customize: Modify pyproject.toml, .pre-commit-config.yaml (if applicable), and GitHub workflow YAMLs as needed.
  3. Develop: Add your code to src/your_package_name/ and tests to tests/.
  4. Document: Update the README and add documentation if necessary.
  5. CI/CD: Utilize the pre-configured GitHub Actions for automated testing.

💡 Contribute

Ultralytics thrives on community contributions! Please see our Contributing Guide for details on how to participate. Share your feedback in our Survey. Thank you 🙏 to all our contributors!

Ultralytics open-source contributors

📄 License

Ultralytics offers two licensing options:

  • AGPL-3.0 License: An OSI-approved open-source license for students, enthusiasts, and researchers. See LICENSE for details.
  • Enterprise License: For commercial use, allowing integration of Ultralytics software and AI models into commercial products without the AGPL-3.0 copyleft restrictions. Contact Ultralytics Licensing if this is required.

📮 Contact

For issues or feature suggestions, please open a GitHub Issue. You can also join our Discord community!


Ultralytics GitHub space Ultralytics LinkedIn space Ultralytics Twitter space Ultralytics YouTube space Ultralytics TikTok space Ultralytics BiliBili space Ultralytics Discord