{"id":15014893,"url":"https://github.com/anntzer/ipython-autoimport","last_synced_at":"2025-04-09T19:23:22.266Z","repository":{"id":53673667,"uuid":"64990467","full_name":"anntzer/ipython-autoimport","owner":"anntzer","description":"Automagically import missing modules in IPython.","archived":false,"fork":false,"pushed_at":"2023-10-19T07:26:25.000Z","size":117,"stargazers_count":56,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2023-10-20T06:12:08.301Z","etag":null,"topics":["ipython"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anntzer.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2016-08-05T05:16:28.000Z","updated_at":"2024-04-27T01:26:42.559Z","dependencies_parsed_at":"2023-01-30T03:15:26.145Z","dependency_job_id":"3571d6ce-3dc7-40a4-88e4-a93917ad53c7","html_url":"https://github.com/anntzer/ipython-autoimport","commit_stats":{"total_commits":63,"total_committers":4,"mean_commits":15.75,"dds":0.04761904761904767,"last_synced_commit":"81ac70129dbdfc29c1a3e89b08eea158e9e682bf"},"previous_names":[],"tags_count":5,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fipython-autoimport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fipython-autoimport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fipython-autoimport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fipython-autoimport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anntzer","download_url":"https://codeload.github.com/anntzer/ipython-autoimport/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248095926,"owners_count":21046943,"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":["ipython"],"created_at":"2024-09-24T19:46:13.710Z","updated_at":"2025-04-09T19:23:22.257Z","avatar_url":"https://github.com/anntzer.png","language":"Python","readme":"ipython-autoimport\n==================\n\n| |GitHub| |PyPI| |Build|\n\n.. |GitHub|\n   image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen\n   :target: https://github.com/anntzer/ipython-autoimport\n.. |PyPI|\n   image:: https://img.shields.io/pypi/v/ipython-autoimport.svg?color=brightgreen\n   :target: https://pypi.python.org/pypi/ipython-autoimport\n.. |Build|\n   image:: https://img.shields.io/github/actions/workflow/status/anntzer/ipython-autoimport/build.yml?branch=main\n   :target: https://github.com/anntzer/ipython-autoimport/actions\n\nAutomagically import missing modules in IPython: instead of ::\n\n   In [1]: plt.plot([1, 2], [3, 4])\n   ---------------------------------------------------------------------------\n   NameError                                 Traceback (most recent call last)\n   \u003cipython-input-1-994ba2bf13c0\u003e in \u003cmodule\u003e()\n   ----\u003e 1 plt.plot([1, 2], [3, 4])\n\n   NameError: name 'plt' is not defined\n\n   In [2]: from matplotlib import pyplot as plt\n\n   In [3]: plt.plot([1, 2], [3, 4])\n   Out[3]: [\u003cmatplotlib.lines.Line2D at 0x7f73f0179198\u003e]\n\ndo what I mean::\n\n   In [1]: plt.plot([1, 2], [3, 4])\n   Autoimport: from matplotlib import pyplot as plt\n   Out[1]: [\u003cmatplotlib.lines.Line2D at 0x7f7e253552b0\u003e]\n\nInspired from @OrangeFlash81's `version\n\u003chttps://github.com/OrangeFlash81/ipython-auto-import\u003e`_, with many\nimprovements:\n\n- Does not rely on re-execution, but instead hooks the user namespace; thus,\n  safe even in the presence of side effects, and works for tab completion and\n  magics too.\n- Learns your preferred aliases from the history -- ``plt`` is not hardcoded to\n  alias ``matplotlib.pyplot``, just found because you previously imported\n  ``pyplot`` under this alias.\n- Suppresses irrelevant chained tracebacks.\n- Auto-imports submodules.\n- ``pip``-installable.\n\nTo see auto imports from the current session: ``%autoimport -l``\n\nTo clear the cache for a symbol with multiple possible imports: ``%autoimport -c SYMBOL``\n\nInstallation\n------------\n\nAs usual, install using pip:\n\n.. code-block:: sh\n\n   $ pip install ipython-autoimport  # from PyPI\n   $ pip install git+https://github.com/anntzer/ipython-autoimport  # from Github\n\nThen, append the output of ``python -m ipython_autoimport`` to the\n``ipython_config.py`` file in the directory printed by ``ipython profile\nlocate`` (typically ``~/.ipython/profile_default/``).  If you don't have such a\nfile at all, first create it with ``ipython profile create``.\n\nWhen using Spyder, the above registration method will not work; instead, add\n``%load_ext ipython_autoimport`` to the\n``Preferences → IPython console → Startup → Run code`` option.\n\nNote that upon loading, ``ipython_autoimport`` will register its submodule\nauto-importer to IPython's \"limited evalutation\" completer policy (on IPython\nversions that support it).\n\nRun tests with ``pytest``.\n\nLimitations\n-----------\n\nConstructs such as ::\n\n   class C:\n      auto_imported_value\n\nwill not work, because they are run using the class locals (rather than the\npatched locals); patching globals would not work because ``LOAD_NAME`` queries\nglobals using ``PyDict_GetItem`` exactly (note that it queries locals using\n``PyObject_GetItem``; also, ``LOAD_GLOBALS`` queries *both* globals and\nbuiltins using ``PyObject_GetItem`` so we could possibly get away with patching\nthe builtins dict instead, but that seems a bit too invasive...).\n\nWhen using Jedi autocompletion (the default if Jedi is installed as of IPython\n7.2), trying to tab-complete not-yet-imported global names to trigger an import\nfailure, because Jedi purposefully converts the global dict to a namespace\nobject and looks up attributes using ``getattr_static``.  Jedi can be disabled\nby adding ``c.Completer.use_jedi = False`` to the ``ipython_config.py`` file.\n\nChangelog\n---------\n\nv0.5.1 (2025-03-11)\n~~~~~~~~~~~~~~~~~~~\n- Fix compatibility with IPython 9's new theme system.\n\nv0.5 (2024-08-20)\n~~~~~~~~~~~~~~~~~\n- Avoid erroring when exiting IPython≥8.15.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanntzer%2Fipython-autoimport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanntzer%2Fipython-autoimport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanntzer%2Fipython-autoimport/lists"}