Skip to main content

Ultralytics autoimport Python Package

Project description

Ultralytics logo

โšก๏ธ autoimport: Effortless Lazy Imports in Python

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

autoimport CI Ultralytics Actions Ultralytics 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 according to standard Python import mechanics:

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()
# The package is actually loaded here when torch.cuda is accessed
torch.cuda.is_available()
print(f"First use time: {time.perf_counter() - t1:.3f}s")  # Example output: 0.462s

In this example, the import torch statement inside the lazy() context doesn't immediately load the PyTorch library. The actual import happens only when torch.cuda.is_available() is called, demonstrating the deferred loading mechanism.

๐Ÿ—‚ 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 using frameworks like pytest.
  • pyproject.toml: Project configuration following PEP 621, including dependencies and packaging details.
  • .gitignore: Specifies files intentionally untracked by Git.
  • LICENSE: The open-source license for the project (AGPL-3.0).
  • .github/workflows/: GitHub Actions workflows for Continuous Integration (CI) and Continuous Deployment (CD).
autoimport/
โ”‚
โ”œโ”€โ”€ autoimport/           # Package source code
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ ...
โ”‚
โ”œโ”€โ”€ tests/                # Unit tests
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_autoimport.py
โ”‚   โ””โ”€โ”€ ...
โ”‚
โ”œโ”€โ”€ pyproject.toml        # Project configuration
โ”œโ”€โ”€ .gitignore            # Git ignore rules
โ”œโ”€โ”€ LICENSE               # AGPL-3.0 License file
โ”œโ”€โ”€ README.md             # This file
โ””โ”€โ”€ .github/workflows/    # GitHub Actions CI/CD workflows
    โ”œโ”€โ”€ ci.yml
    โ””โ”€โ”€ format.yml

๐Ÿ“‚ Source Code in autoimport/ Directory

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

๐Ÿงช Testing with the tests/ Directory

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

โž• 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 repository as a template to generate a new one for your project.
  2. Customize: Modify pyproject.toml, .pre-commit-config.yaml (if using pre-commit), and GitHub workflow YAML files as needed for your specific project requirements.
  3. Develop: Add your source code to a new directory (e.g., your_package_name/) and corresponding tests to the tests/ directory.
  4. Document: Update the README.md file and add any necessary documentation within the Ultralytics Docs.
  5. CI/CD: Utilize the pre-configured GitHub Actions for automated testing and formatting checks.

๐Ÿ’ก Contribute

Ultralytics thrives on community contributions! We appreciate any help, from reporting bugs to submitting pull requests. Please see our Contributing Guide for more details on how to get involved. You can also share your feedback through our quick Survey. Thank you ๐Ÿ™ to all our contributors!

Ultralytics open-source contributors

๐Ÿ“„ License

Ultralytics provides two licensing options to accommodate different use cases:

  • AGPL-3.0 License: This OSI-approved open-source license is ideal for students, enthusiasts, and researchers who wish to share their work openly. See the LICENSE file for full details.
  • Enterprise License: Designed for commercial use, this license allows for the integration of Ultralytics software and AI models into commercial products and services without the open-source requirements of AGPL-3.0. Please contact Ultralytics Licensing for more information.

๐Ÿ“ฎ Contact

For bug reports, feature requests, or questions, please open a GitHub Issue. For community support and discussions, join our Discord server!


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

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

ultralytics_autoimport-0.0.4.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

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

ultralytics_autoimport-0.0.4-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file ultralytics_autoimport-0.0.4.tar.gz.

File metadata

  • Download URL: ultralytics_autoimport-0.0.4.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ultralytics_autoimport-0.0.4.tar.gz
Algorithm Hash digest
SHA256 0a90f262ec9b6ca733ac49796c1090446bde1557d583463d1df49caaf750f999
MD5 8ef6d8afddca7c75a443178101e45a4a
BLAKE2b-256 dc4311757de3f92ab41680eb358c2fdab4438a23a50cbc0bc444e13d157adb6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_autoimport-0.0.4.tar.gz:

Publisher: publish.yml on ultralytics/autoimport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ultralytics_autoimport-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for ultralytics_autoimport-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7923fb72fc44c0f70789824b103e80aa96f1ca966447fcc402068aa9d984b81c
MD5 2cb48ae77db79b39af6fb4b0040a8cb9
BLAKE2b-256 10cfbf99443ad3ff65e239e801fbbec46800e0405f656f2def557ff62736c38d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ultralytics_autoimport-0.0.4-py3-none-any.whl:

Publisher: publish.yml on ultralytics/autoimport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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