{"id":31658099,"url":"https://github.com/ok97465/py-autoimport.nvim","last_synced_at":"2026-05-04T08:42:14.767Z","repository":{"id":314460881,"uuid":"1055581624","full_name":"ok97465/py-autoimport.nvim","owner":"ok97465","description":"Auto-import undefined Python symbols from your workspace.","archived":false,"fork":false,"pushed_at":"2025-10-18T07:12:32.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-28T18:41:09.286Z","etag":null,"topics":["autoimport","lua","nvim","python"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ok97465.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-12T13:34:10.000Z","updated_at":"2025-10-18T07:12:35.000Z","dependencies_parsed_at":"2025-09-12T16:56:25.565Z","dependency_job_id":"97f9e70e-7a38-4bee-9c1a-bd23795f27ab","html_url":"https://github.com/ok97465/py-autoimport.nvim","commit_stats":null,"previous_names":["ok97465/py-autoimport.nvim"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ok97465/py-autoimport.nvim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ok97465%2Fpy-autoimport.nvim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ok97465%2Fpy-autoimport.nvim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ok97465%2Fpy-autoimport.nvim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ok97465%2Fpy-autoimport.nvim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ok97465","download_url":"https://codeload.github.com/ok97465/py-autoimport.nvim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ok97465%2Fpy-autoimport.nvim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32600967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"online","status_checked_at":"2026-05-04T02:00:06.625Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["autoimport","lua","nvim","python"],"created_at":"2025-10-07T15:12:31.005Z","updated_at":"2026-05-04T08:42:14.761Z","avatar_url":"https://github.com/ok97465.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# py-autoimport.nvim\n\nAuto-import undefined Python symbols from your workspace. Neovim 0.11+ only.\n\n## Overview\n\n- Detects undefined names via Ruff (pyflakes F821) diagnostics in the current buffer.\n- First tries project JSON maps (`autoimport_for_python.json`, `autoimport_for_project.json`) to import known aliases/modules (e.g., `np` -\u003e `import numpy as np`). If not found, searches the workspace with ripgrep for top-level definitions and inserts an appropriate `from pkg.mod import Name`.\n- Respects isort section headers when present (`pyproject.toml`, `.isort.cfg`, `setup.cfg`, `tox.ini`).\n- Falls back to default headers (including `# %% Import`).\n\n## Requirements\n\n- Neovim 0.11+\n- Ruff diagnostics exposed to Neovim (e.g., via the `ruff` server)\n- ripgrep (`rg`) in your `PATH`\n- Optional: `vim-isort` (or any command that formats/import-sorts), default command: `Isort`\n\n## Installation (example)\n\n```vim\nPlug 'fisadev/vim-isort'         \" optional, to sort/dedupe imports\nPlug 'ok97465/py-autoimport.nvim'\n```\n\n## Setup\n\n```lua\nrequire('py_autoimport').setup({\n  search = {\n    globs_include = { '*.py' },\n    globs_exclude = { '.venv/**', 'venv/**', '__pycache__/**', 'build/**', 'dist/**' },\n    include_variables = true,                -- also search variables\n    include_annotations_without_value = false,\n  },\n  insert = {\n    docstring_scan_lines = 50,\n    import_scan_lines = 300,\n    isort_command = 'Isort',                 -- set to nil to disable\n    add_trailing_blank_line = true,\n    header_markers = {\n      '# %% Import',\n      '# Standard library imports',\n      '# Local imports',\n      '# Third party imports',\n    },\n  },\n  path = { collapse_dunder_init = true },    -- pkg/__init__.py -\u003e pkg\n})\n```\n\n### Ruff Server Setup (vim.lsp)\n\nEnsure the Ruff language server is attached so this plugin can read F821 undefined-name reports.\n\n```lua\nlocal ruff_inline_config = {\n  -- Optional Ruff settings; adjust to your project needs.\n}\n\nvim.lsp.config('ruff', {\n  init_options = {\n    settings = {\n      configuration = ruff_inline_config,\n    },\n  },\n})\n\nvim.lsp.enable('ruff')\n```\n\n## Usage\n\n```\n:PyAutoImport\n```\n\n- Scans the current buffer for undefined names reported by Ruff, searches the workspace, inserts imports, then runs `Isort` if configured.\n- JSON maps take precedence; if both JSONs are missing or no match exists, workspace search is used. When both JSONs are present, their union is used (project overrides per-key).\n- If multiple matches exist, the first match is used (closest to project root). Improvements like interactive selection can be added later.\n\n## Create autoimport_for_python.json\n\nYou can define project-specific import rules with a JSON file placed in your project root (the Neovim working directory).\n\n- Recognized files: `autoimport_for_python.json`, `autoimport_for_project.json`\n- Merge and precedence: both are optional; when both exist, their union is used and `autoimport_for_project.json` overrides per symbol. If neither exists, the plugin’s default map at `data/autoimport_for_python.json` is used.\n\nStructure of the JSON:\n\n- alias: map of alias to module string\n  - Generates `import \u003cmodule\u003e` when alias == module\n  - Generates `import \u003cmodule\u003e as \u003calias\u003e` when alias != module\n- module: map of module path to symbols to import\n  - Value can be a single string or a list of strings\n  - Generates `from \u003cmodule\u003e import \u003cName\u003e` for each symbol\n\nExample `autoimport_for_python.json`:\n\n```json\n{\n  \"alias\": {\n    \"np\": \"numpy\",\n    \"plt\": \"matplotlib.pyplot\",\n    \"os\": \"os\"            \n  },\n  \"module\": {\n    \"numpy.linalg\": [\"norm\", \"inv\"],\n    \"pathlib\": \"Path\",\n    \"pandas\": [\"DataFrame\", \"Series\"]\n  }\n}\n```\n\nNotes:\n\n- The file must be valid JSON (no comments). UTF-8 is recommended.\n- When multiple candidates exist for the same symbol, the first one in the resolved map is used.\n- Run `:PyAutoImport` to apply your rules; JSON mappings are applied before workspace search.\n\n## Notes\n\n- Requires Ruff diagnostics to be available for the buffer; no Treesitter is required.\n- Errors are reported via `vim.notify` under the title `py-autoimport`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fok97465%2Fpy-autoimport.nvim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fok97465%2Fpy-autoimport.nvim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fok97465%2Fpy-autoimport.nvim/lists"}