{"id":28818327,"url":"https://github.com/ultralytics/autoimport","last_synced_at":"2025-07-19T10:38:34.286Z","repository":{"id":272771728,"uuid":"917704436","full_name":"ultralytics/autoimport","owner":"ultralytics","description":"Effortless lazy Python imports","archived":false,"fork":false,"pushed_at":"2025-05-11T00:22:18.000Z","size":51,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-18T23:44:17.865Z","etag":null,"topics":["best-practices","code","imports","lazy","lazy-loading","lazyload","python","tools","ultralytics","yolo"],"latest_commit_sha":null,"homepage":"https://ultralytics.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ultralytics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"glenn-jocher","patreon":"ultralytics","open_collective":"ultralytics"}},"created_at":"2025-01-16T13:49:58.000Z","updated_at":"2025-07-02T22:38:11.000Z","dependencies_parsed_at":"2025-01-16T15:16:51.731Z","dependency_job_id":"f2fa3e74-72f7-4868-8f10-3570bc8a97ec","html_url":"https://github.com/ultralytics/autoimport","commit_stats":null,"previous_names":["ultralytics/autoimport"],"tags_count":4,"template":false,"template_full_name":"ultralytics/template","purl":"pkg:github/ultralytics/autoimport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultralytics%2Fautoimport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultralytics%2Fautoimport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultralytics%2Fautoimport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultralytics%2Fautoimport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ultralytics","download_url":"https://codeload.github.com/ultralytics/autoimport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultralytics%2Fautoimport/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265919275,"owners_count":23849346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["best-practices","code","imports","lazy","lazy-loading","lazyload","python","tools","ultralytics","yolo"],"created_at":"2025-06-18T19:04:10.250Z","updated_at":"2025-07-19T10:38:34.277Z","avatar_url":"https://github.com/ultralytics.png","language":"Python","funding_links":["https://github.com/sponsors/glenn-jocher","https://patreon.com/ultralytics","https://opencollective.com/ultralytics"],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://www.ultralytics.com/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg\" width=\"320\" alt=\"Ultralytics logo\"\u003e\u003c/a\u003e\n\n# ⚡️ `autoimport`: Effortless Lazy Imports in Python\n\n`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](https://pypi.org/project/ultralytics-autoimport/) for easy installation.\n\n[![autoimport CI](https://github.com/ultralytics/autoimport/actions/workflows/ci.yml/badge.svg)](https://github.com/ultralytics/autoimport/actions/workflows/ci.yml)\n[![Ultralytics Actions](https://github.com/ultralytics/autoimport/actions/workflows/format.yml/badge.svg)](https://github.com/ultralytics/autoimport/actions/workflows/format.yml)\n[![Ultralytics Discord](https://img.shields.io/discord/1089800235347353640?logo=discord\u0026logoColor=white\u0026label=Discord\u0026color=blue)](https://discord.com/invite/ultralytics)\n[![Ultralytics Forums](https://img.shields.io/discourse/users?server=https%3A%2F%2Fcommunity.ultralytics.com\u0026logo=discourse\u0026label=Forums\u0026color=blue)](https://community.ultralytics.com/)\n[![Ultralytics Reddit](https://img.shields.io/reddit/subreddit-subscribers/ultralytics?style=flat\u0026logo=reddit\u0026logoColor=white\u0026label=Reddit\u0026color=blue)](https://reddit.com/r/ultralytics)\n\n## 🚀 Quick Start\n\nInstall the `ultralytics-autoimport` package from [PyPI](https://pypi.org/project/ultralytics-autoimport/):\n\n[![PyPI - Version](https://img.shields.io/pypi/v/ultralytics-autoimport.svg)](https://pypi.org/project/ultralytics-autoimport/)\n[![Downloads](https://static.pepy.tech/badge/ultralytics-autoimport)](https://www.pepy.tech/projects/ultralytics-autoimport)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ultralytics-autoimport.svg)](https://pypi.org/project/ultralytics-autoimport/)\n\n```bash\npip install ultralytics-autoimport\n```\n\nUse the `lazy` context manager to defer imports according to standard [Python import mechanics](https://docs.python.org/3/reference/import.html):\n\n```python\nimport time\n\nfrom autoimport import lazy\n\nwith lazy():\n    t0 = time.perf_counter()\n    import torch  # Import is deferred until first use\n\n    print(f\"Initial import time: {time.perf_counter() - t0:.3f}s\")  # Example output: 0.000s\n\nt1 = time.perf_counter()\n# The package is actually loaded here when torch.cuda is accessed\ntorch.cuda.is_available()\nprint(f\"First use time: {time.perf_counter() - t1:.3f}s\")  # Example output: 0.462s\n```\n\nIn this example, the `import torch` statement inside the `lazy()` context doesn't immediately load the [PyTorch](https://pytorch.org/) library. The actual import happens only when `torch.cuda.is_available()` is called, demonstrating the deferred loading mechanism.\n\n## 🗂 Repository Structure\n\nThe repository is organized for clarity and ease of development:\n\n- `autoimport/`: Contains the source code of the `autoimport` package.\n- `tests/`: Unit tests to ensure code reliability using frameworks like [pytest](https://docs.pytest.org/en/stable/).\n- `pyproject.toml`: Project configuration following [PEP 621](https://peps.python.org/pep-0621/), including dependencies and packaging details.\n- `.gitignore`: Specifies files intentionally untracked by Git.\n- `LICENSE`: The open-source license for the project ([AGPL-3.0](https://opensource.org/license/agpl-v3)).\n- `.github/workflows/`: [GitHub Actions](https://docs.github.com/en/actions) workflows for Continuous Integration (CI) and Continuous Deployment (CD).\n\n```\nautoimport/\n│\n├── autoimport/           # Package source code\n│   ├── __init__.py\n│   └── ...\n│\n├── tests/                # Unit tests\n│   ├── __init__.py\n│   ├── test_autoimport.py\n│   └── ...\n│\n├── pyproject.toml        # Project configuration\n├── .gitignore            # Git ignore rules\n├── LICENSE               # AGPL-3.0 License file\n├── README.md             # This file\n└── .github/workflows/    # GitHub Actions CI/CD workflows\n    ├── ci.yml\n    └── format.yml\n```\n\n### 📂 Source Code in `autoimport/` Directory\n\nThe `autoimport/` directory contains the core Python code for the `autoimport` package.\n\n### 🧪 Testing with the `tests/` Directory\n\nThe `tests/` directory includes tests designed to maintain code quality and prevent regressions during development.\n\n## ➕ Starting a New Project\n\nThis repository can also serve as a template for new Python projects at [Ultralytics](https://www.ultralytics.com/).\n\nTo use it as a template:\n\n1.  **Create a New Repository:** Use this repository as a template to generate a new one for your project.\n2.  **Customize:** Modify `pyproject.toml`, `.pre-commit-config.yaml` (if using [pre-commit](https://pre-commit.com/)), and GitHub workflow YAML files as needed for your specific project requirements.\n3.  **Develop:** Add your source code to a new directory (e.g., `your_package_name/`) and corresponding tests to the `tests/` directory.\n4.  **Document:** Update the README.md file and add any necessary documentation within the [Ultralytics Docs](https://docs.ultralytics.com/).\n5.  **CI/CD:** Utilize the pre-configured [GitHub Actions](https://docs.github.com/en/actions) for automated testing and formatting checks.\n\n## 💡 Contribute\n\nUltralytics thrives on community contributions! We appreciate any help, from reporting bugs to submitting pull requests. Please see our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for more details on how to get involved. You can also share your feedback through our quick [Survey](https://www.ultralytics.com/survey?utm_source=github\u0026utm_medium=social\u0026utm_campaign=Survey). Thank you 🙏 to all our contributors!\n\n[![Ultralytics open-source contributors](https://raw.githubusercontent.com/ultralytics/assets/main/im/image-contributors.png)](https://github.com/ultralytics/autoimport/graphs/contributors)\n\n## 📄 License\n\nUltralytics provides two licensing options to accommodate different use cases:\n\n- **AGPL-3.0 License**: This [OSI-approved](https://opensource.org/license) open-source license is ideal for students, enthusiasts, and researchers who wish to share their work openly. See the [LICENSE](https://github.com/ultralytics/autoimport/blob/main/LICENSE) file for full details.\n- **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](https://www.ultralytics.com/license) for more information.\n\n## 📮 Contact\n\nFor bug reports, feature requests, or questions, please open a [GitHub Issue](https://github.com/ultralytics/autoimport/issues). For community support and discussions, join our [Discord](https://discord.com/invite/ultralytics) server!\n\n\u003cbr\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ultralytics\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-github.png\" width=\"3%\" alt=\"Ultralytics GitHub\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://www.linkedin.com/company/ultralytics/\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-linkedin.png\" width=\"3%\" alt=\"Ultralytics LinkedIn\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://twitter.com/ultralytics\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-twitter.png\" width=\"3%\" alt=\"Ultralytics Twitter\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://youtube.com/ultralytics?sub_confirmation=1\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-youtube.png\" width=\"3%\" alt=\"Ultralytics YouTube\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://www.tiktok.com/@ultralytics\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png\" width=\"3%\" alt=\"Ultralytics TikTok\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://ultralytics.com/bilibili\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png\" width=\"3%\" alt=\"Ultralytics BiliBili\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png\" width=\"3%\" alt=\"space\"\u003e\n  \u003ca href=\"https://discord.com/invite/ultralytics\"\u003e\u003cimg src=\"https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png\" width=\"3%\" alt=\"Ultralytics Discord\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultralytics%2Fautoimport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fultralytics%2Fautoimport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultralytics%2Fautoimport/lists"}