Ultralytics autoimport Python Package
Project description
โก๏ธ 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.
๐ Quick Start
Install the ultralytics-autoimport package from PyPI:
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 theautoimportpackage.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:
- Create a New Repository: Use this repository as a template to generate a new one for your project.
- Customize: Modify
pyproject.toml,.pre-commit-config.yaml(if using pre-commit), and GitHub workflow YAML files as needed for your specific project requirements. - Develop: Add your source code to a new directory (e.g.,
your_package_name/) and corresponding tests to thetests/directory. - Document: Update the README.md file and add any necessary documentation within the Ultralytics Docs.
- 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!
๐ 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!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a90f262ec9b6ca733ac49796c1090446bde1557d583463d1df49caaf750f999
|
|
| MD5 |
8ef6d8afddca7c75a443178101e45a4a
|
|
| BLAKE2b-256 |
dc4311757de3f92ab41680eb358c2fdab4438a23a50cbc0bc444e13d157adb6d
|
Provenance
The following attestation bundles were made for ultralytics_autoimport-0.0.4.tar.gz:
Publisher:
publish.yml on ultralytics/autoimport
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultralytics_autoimport-0.0.4.tar.gz -
Subject digest:
0a90f262ec9b6ca733ac49796c1090446bde1557d583463d1df49caaf750f999 - Sigstore transparency entry: 452868010
- Sigstore integration time:
-
Permalink:
ultralytics/autoimport@f6540f5bc6ad5ccbb08088b9262329e1f6d0f012 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ultralytics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f6540f5bc6ad5ccbb08088b9262329e1f6d0f012 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ultralytics_autoimport-0.0.4-py3-none-any.whl.
File metadata
- Download URL: ultralytics_autoimport-0.0.4-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7923fb72fc44c0f70789824b103e80aa96f1ca966447fcc402068aa9d984b81c
|
|
| MD5 |
2cb48ae77db79b39af6fb4b0040a8cb9
|
|
| BLAKE2b-256 |
10cfbf99443ad3ff65e239e801fbbec46800e0405f656f2def557ff62736c38d
|
Provenance
The following attestation bundles were made for ultralytics_autoimport-0.0.4-py3-none-any.whl:
Publisher:
publish.yml on ultralytics/autoimport
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ultralytics_autoimport-0.0.4-py3-none-any.whl -
Subject digest:
7923fb72fc44c0f70789824b103e80aa96f1ca966447fcc402068aa9d984b81c - Sigstore transparency entry: 452868012
- Sigstore integration time:
-
Permalink:
ultralytics/autoimport@f6540f5bc6ad5ccbb08088b9262329e1f6d0f012 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ultralytics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f6540f5bc6ad5ccbb08088b9262329e1f6d0f012 -
Trigger Event:
push
-
Statement type: