##// END OF EJS Templates
Describe using PyPI/pip to distribute & install extensions...
Thomas Kluyver -
Show More
@@ -1,92 +1,100
1 1 .. _extensions_overview:
2 2
3 3 ==================
4 4 IPython extensions
5 5 ==================
6 6
7 7 A level above configuration are IPython extensions, Python modules which modify
8 8 the behaviour of the shell. They are referred to by an importable module name,
9 9 and can be placed anywhere you'd normally import from, or in
10 10 ``.ipython/extensions/``.
11 11
12 12 Getting extensions
13 13 ==================
14 14
15 15 A few important extensions are :ref:`bundled with IPython <bundled_extensions>`.
16 16 Others can be found on the `extensions index
17 <https://github.com/ipython/ipython/wiki/Extensions-Index>`_ on the wiki, and installed with
18 the ``%install_ext`` magic function.
17 <https://github.com/ipython/ipython/wiki/Extensions-Index>`_ on the wiki, and
18 the `Framework :: IPython tag <https://pypi.python.org/pypi?:action=browse&c=586>`_
19 on PyPI.
20
21 Extensions on PyPI can be installed using ``pip``, like any other Python package.
22 Other simple extensions can be installed with the ``%install_ext`` magic. The
23 latter does no validation, so be careful using it on untrusted networks like
24 public wifi.
19 25
20 26 Using extensions
21 27 ================
22 28
23 29 To load an extension while IPython is running, use the ``%load_ext`` magic:
24 30
25 31 .. sourcecode:: ipython
26 32
27 33 In [1]: %load_ext myextension
28 34
29 35 To load it each time IPython starts, list it in your configuration file::
30 36
31 37 c.InteractiveShellApp.extensions = [
32 38 'myextension'
33 39 ]
34 40
35 41 Writing extensions
36 42 ==================
37 43
38 44 An IPython extension is an importable Python module that has a couple of special
39 45 functions to load and unload it. Here is a template::
40 46
41 47 # myextension.py
42 48
43 49 def load_ipython_extension(ipython):
44 50 # The `ipython` argument is the currently active `InteractiveShell`
45 51 # instance, which can be used in any way. This allows you to register
46 52 # new magics or aliases, for example.
47 53
48 54 def unload_ipython_extension(ipython):
49 55 # If you want your extension to be unloadable, put that logic here.
50 56
51 57 This :func:`load_ipython_extension` function is called after your extension is
52 58 imported, and the currently active :class:`~IPython.core.interactiveshell.InteractiveShell`
53 59 instance is passed as the only argument. You can do anything you want with
54 60 IPython at that point.
55 61
56 62 :func:`load_ipython_extension` will be called again if you load or reload
57 63 the extension again. It is up to the extension author to add code to manage
58 64 that.
59 65
60 66 Useful :class:`InteractiveShell` methods include :meth:`~IPython.core.interactiveshell.InteractiveShell.register_magic_function`,
61 67 :meth:`~IPython.core.interactiveshell.InteractiveShell.push` (to add variables to the user namespace) and
62 68 :meth:`~IPython.core.interactiveshell.InteractiveShell.drop_by_id` (to remove variables on unloading).
63 69
64 70 .. seealso::
65 71
66 72 :ref:`defining_magics`
67 73
68 74 You can put your extension modules anywhere you want, as long as they can be
69 75 imported by Python's standard import mechanism. However, to make it easy to
70 76 write extensions, you can also put your extensions in :file:`extensions/`
71 77 within the :ref:`IPython directory <ipythondir>`. This directory is
72 78 added to :data:`sys.path` automatically.
73 79
74 80 When your extension is ready for general use, please add it to the `extensions
75 index <https://github.com/ipython/ipython/wiki/Extensions-Index>`_.
81 index <https://github.com/ipython/ipython/wiki/Extensions-Index>`_. We also
82 encourage you to upload it to PyPI and use the ``Framework :: IPython``
83 classifier, so that users can install it with standard packaging tools.
76 84
77 85 .. _bundled_extensions:
78 86
79 87 Extensions bundled with IPython
80 88 ===============================
81 89
82 90 .. toctree::
83 91 :maxdepth: 1
84 92
85 93 autoreload
86 94 cythonmagic
87 95 rmagic
88 96 storemagic
89 97 sympyprinting
90 98
91 99 * ``octavemagic`` used to be bundled, but is now part of `oct2py <http://blink1073.github.io/oct2py/docs/>`_.
92 100 Use ``%load_ext oct2py.ipython`` to load it.
General Comments 0
You need to be logged in to leave comments. Login now