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