https://github.com/karimaziev/pyimp
An Emacs library for inserting Python import statements.
https://github.com/karimaziev/pyimp
emacs emacs-package python python-imports
Last synced: 30 days ago
JSON representation
An Emacs library for inserting Python import statements.
- Host: GitHub
- URL: https://github.com/karimaziev/pyimp
- Owner: KarimAziev
- License: gpl-3.0
- Created: 2024-09-08T07:21:20.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2026-02-01T09:49:04.000Z (about 2 months ago)
- Last Synced: 2026-02-01T19:59:51.065Z (about 2 months ago)
- Topics: emacs, emacs-package, python, python-imports
- Language: Emacs Lisp
- Homepage:
- Size: 130 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+OPTIONS: ^:nil tags:nil num:nil
* About
=pyimp= is an Emacs library that helps you insert Python import statements.
*Why*
While many LSP servers assume you’re typing a symbol and then rely on auto-import completions, they may fall short in scenarios where:
- The desired symbol isn’t immediately suggested.
- You’re pasting code or otherwise not triggering completions.
- You remember the module but not the symbol name.
=pyimp= fills this gap by giving you precise control over import statements. This tool can work alongside your LSP server or serve as a standalone solution for handling Python imports in Emacs.
* Table of Contents :TOC_2_gh:QUOTE:
#+BEGIN_QUOTE
- [[#about][About]]
- [[#requirements][Requirements]]
- [[#installation][Installation]]
- [[#with-use-package-and-straightel][With use-package and straight.el]]
- [[#manual-installation][Manual installation]]
- [[#usage][Usage]]
- [[#configuration-and-customization][Configuration and Customization]]
#+END_QUOTE
* Requirements
| Name | Version |
|------------------------------+---------|
| Emacs with =treesit= support | 29.1 |
| pyvenv | 1.21 |
* Installation
** With use-package and straight.el
#+begin_src elisp :eval no
(use-package pyimp
:straight (pyimp
:repo "KarimAziev/pyimp"
:type git
:host github
:flavor nil)
:bind ((:map pyimp-modules-minibuffer-map
("C-j" . pyimp-describe-module)
("C-c C-o" . pyimp-abort-minibuffer-and-describe-module)))
:commands (pyimp-import))
#+end_src
** Manual installation
Download the source code and put it wherever you like, e.g. into =~/.emacs.d/pyimp/=
#+begin_src shell :eval no
git clone https://github.com/KarimAziev/pyimp.git ~/.emacs.d/pyimp/
#+end_src
Add the downloaded directory to the load path:
#+begin_src elisp :eval no
(add-to-list 'load-path "~/.emacs.d/pyimp/")
(require 'pyimp)
#+end_src
* Usage
Invoke the command =pyimp-import= (for example via =M-x= or a bound key) to insert an import statement. The process works as follows:
1. You will be prompted for a Python module. pyimp searches your project, installed libraries, and built-in modules.
2. After selecting a module, pyimp presents a list of exported symbols from the module. You can choose a single symbol or mark multiple symbols (if you enable minibuffer marking).
3. Once selected, pyimp automatically inserts or updates the appropriate import statement in your Python file.
If you ever need to read module documentation or review what's been imported, you can use the provided module description functionality (bound under =C-j= by default).
* Configuration and Customization
=pyimp= provides several customizable variables. For instance:
- =pyimp-files-sorting-threshold=
Sets the threshold (in number of files) that determines whether project files should be sorted.
(Set to nil to always sort.)
- =pyimp-allow-minibuffer-marking=
If enabled, lets you mark multiple symbols in the minibuffer for import. If enabled, you may want to customize =pyimp-multiple-symbols-minibuffer-map=:
#+begin_src elisp
(use-package pyimp
:straight (pyimp
:repo "KarimAziev/pyimp"
:type git
:host github
:flavor nil)
:bind ((:map pyimp-multiple-symbols-minibuffer-map
("RET" . pyimp-minibuffer-done)
("C-SPC" . pyimp-minibuffer-mark)
("C-" . pyimp-minibuffer-done)
("C-M-j" . pyimp-minibuffer-done)))
:commands (pyimp-import))
#+end_src
- =pyimp-extract-module-export-functions=
A hook variable that specifies functions used to extract exported symbols from a module.