Show More
@@ -1,88 +1,90 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 |
|
2 | |||
3 | from IPython.utils.text import indent, wrap_paragraphs |
|
3 | from IPython.utils.text import indent, wrap_paragraphs | |
4 |
|
4 | |||
5 | from IPython.terminal.ipapp import TerminalIPythonApp |
|
5 | from IPython.terminal.ipapp import TerminalIPythonApp | |
6 | from IPython.kernel.zmq.kernelapp import IPKernelApp |
|
6 | from IPython.kernel.zmq.kernelapp import IPKernelApp | |
7 | from IPython.html.notebookapp import NotebookApp |
|
7 | from IPython.html.notebookapp import NotebookApp | |
8 |
|
8 | |||
9 | def document_config_options(classes): |
|
9 | def document_config_options(classes): | |
10 | lines = [] |
|
10 | lines = [] | |
11 | for cls in classes: |
|
11 | for cls in classes: | |
12 | classname = cls.__name__ |
|
12 | classname = cls.__name__ | |
13 | for k, trait in sorted(cls.class_traits(config=True).items()): |
|
13 | for k, trait in sorted(cls.class_traits(config=True).items()): | |
14 | ttype = trait.__class__.__name__ |
|
14 | ttype = trait.__class__.__name__ | |
15 |
|
15 | |||
16 | termline = classname + '.' + trait.name |
|
16 | termline = classname + '.' + trait.name | |
17 |
|
17 | |||
18 | # Choices or type |
|
18 | # Choices or type | |
19 | if 'Enum' in ttype: |
|
19 | if 'Enum' in ttype: | |
20 | # include Enum choices |
|
20 | # include Enum choices | |
21 | termline += ' : ' + '|'.join(repr(x) for x in trait.values) |
|
21 | termline += ' : ' + '|'.join(repr(x) for x in trait.values) | |
22 | else: |
|
22 | else: | |
23 | termline += ' : ' + ttype |
|
23 | termline += ' : ' + ttype | |
24 | lines.append(termline) |
|
24 | lines.append(termline) | |
25 |
|
25 | |||
26 | # Default value |
|
26 | # Default value | |
27 | try: |
|
27 | try: | |
28 | dv = trait.get_default_value() |
|
28 | dv = trait.get_default_value() | |
29 | dvr = repr(dv) |
|
29 | dvr = repr(dv) | |
30 | except Exception: |
|
30 | except Exception: | |
31 | dvr = dv = None # ignore defaults we can't construct |
|
31 | dvr = dv = None # ignore defaults we can't construct | |
32 | if (dv is not None) and (dvr is not None): |
|
32 | if (dv is not None) and (dvr is not None): | |
33 | if len(dvr) > 64: |
|
33 | if len(dvr) > 64: | |
34 | dvr = dvr[:61]+'...' |
|
34 | dvr = dvr[:61]+'...' | |
35 | # Double up backslashes, so they get to the rendered docs |
|
35 | # Double up backslashes, so they get to the rendered docs | |
36 | dvr = dvr.replace('\\n', '\\\\n') |
|
36 | dvr = dvr.replace('\\n', '\\\\n') | |
37 | lines.append(' Default: ' + dvr) |
|
37 | lines.append(' Default: ' + dvr) | |
38 | lines.append('') |
|
38 | lines.append('') | |
39 |
|
39 | |||
40 | help = trait.get_metadata('help') |
|
40 | help = trait.get_metadata('help') | |
41 | if help is not None: |
|
41 | if help is not None: | |
42 | help = '\n\n'.join(wrap_paragraphs(help, 76)) |
|
42 | help = '\n\n'.join(wrap_paragraphs(help, 76)) | |
43 | lines.append(indent(help, 4)) |
|
43 | lines.append(indent(help, 4)) | |
44 | else: |
|
44 | else: | |
45 | lines.append(' No description') |
|
45 | lines.append(' No description') | |
46 |
|
46 | |||
47 | lines.append('') |
|
47 | lines.append('') | |
48 | return '\n'.join(lines) |
|
48 | return '\n'.join(lines) | |
49 |
|
49 | |||
50 | kernel_classes = IPKernelApp().classes |
|
50 | kernel_classes = IPKernelApp().classes | |
51 |
|
51 | |||
52 | def write_doc(name, title, classes, preamble=None): |
|
52 | def write_doc(name, title, classes, preamble=None): | |
53 | configdoc = document_config_options(classes) |
|
53 | configdoc = document_config_options(classes) | |
54 | filename = '%s.rst' % name |
|
54 | filename = '%s.rst' % name | |
55 | with open('source/config/options/%s' % filename, 'w') as f: |
|
55 | with open('source/config/options/%s' % filename, 'w') as f: | |
56 | f.write(title + '\n') |
|
56 | f.write(title + '\n') | |
57 | f.write(('=' * len(title)) + '\n') |
|
57 | f.write(('=' * len(title)) + '\n') | |
58 | f.write('\n') |
|
58 | f.write('\n') | |
59 | if preamble is not None: |
|
59 | if preamble is not None: | |
60 | f.write(preamble + '\n\n') |
|
60 | f.write(preamble + '\n\n') | |
61 | f.write(configdoc) |
|
61 | f.write(configdoc) | |
62 | with open('source/config/options/generated', 'a') as f: |
|
62 | with open('source/config/options/generated', 'a') as f: | |
63 | f.write(filename + '\n') |
|
63 | f.write(filename + '\n') | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | if __name__ == '__main__': |
|
66 | if __name__ == '__main__': | |
67 | # create empty file |
|
67 | # create empty file | |
68 | with open('source/config/options/generated', 'w'): |
|
68 | with open('source/config/options/generated', 'w'): | |
69 | pass |
|
69 | pass | |
70 |
|
70 | |||
71 | write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes) |
|
71 | write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes) | |
72 | write_doc('kernel', 'IPython kernel options', kernel_classes, |
|
72 | write_doc('kernel', 'IPython kernel options', kernel_classes, | |
73 |
|
|
73 | preamble="These options can be used in :file:`ipython_kernel_config.py`", | |
74 | "or in :file:`ipython_qtconsole_config.py`") |
|
74 | ) | |
75 | nbclasses = set(NotebookApp().classes) - set(kernel_classes) |
|
75 | nbclasses = set(NotebookApp().classes) - set(kernel_classes) | |
76 | write_doc('notebook', 'IPython notebook options', nbclasses, |
|
76 | write_doc('notebook', 'IPython notebook options', nbclasses, | |
77 | preamble="Any of the :doc:`kernel` can also be used.") |
|
77 | preamble="To configure the IPython kernel, see :doc:`kernel`." | |
|
78 | ) | |||
78 |
|
79 | |||
79 | try: |
|
80 | try: | |
80 | from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp |
|
81 | from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp | |
81 | except ImportError: |
|
82 | except ImportError: | |
82 | print("WARNING: Could not import qtconsoleapp. Config options for the " |
|
83 | print("WARNING: Could not import qtconsoleapp. Config options for the " | |
83 | "Qt Console will not be documented.") |
|
84 | "Qt Console will not be documented.") | |
84 | else: |
|
85 | else: | |
85 | qtclasses = set(IPythonQtConsoleApp().classes) - set(kernel_classes) |
|
86 | qtclasses = set(IPythonQtConsoleApp().classes) - set(kernel_classes) | |
86 | write_doc('qtconsole', 'IPython Qt console options', qtclasses, |
|
87 | write_doc('qtconsole', 'IPython Qt console options', qtclasses, | |
87 | preamble="Any of the :doc:`kernel` can also be used.") |
|
88 | preamble="To configure the IPython kernel, see :doc:`kernel`." | |
|
89 | ) | |||
88 |
|
90 |
@@ -1,159 +1,156 b'' | |||||
1 | .. _working_remotely: |
|
1 | .. _working_remotely: | |
2 |
|
2 | |||
3 | Running a notebook server |
|
3 | Running a notebook server | |
4 | ========================= |
|
4 | ========================= | |
5 |
|
5 | |||
6 |
|
6 | |||
7 | The :ref:`IPython notebook <htmlnotebook>` web-application is based on a |
|
7 | The :ref:`IPython notebook <htmlnotebook>` web-application is based on a | |
8 | server-client structure. This server uses a :ref:`two-process kernel |
|
8 | server-client structure. This server uses a :ref:`two-process kernel | |
9 | architecture <ipythonzmq>` based on ZeroMQ_, as well as Tornado_ for serving |
|
9 | architecture <ipythonzmq>` based on ZeroMQ_, as well as Tornado_ for serving | |
10 | HTTP requests. By default, a notebook server runs on http://127.0.0.1:8888/ |
|
10 | HTTP requests. By default, a notebook server runs on http://127.0.0.1:8888/ | |
11 | and is accessible only from `localhost`. This document describes how you can |
|
11 | and is accessible only from `localhost`. This document describes how you can | |
12 | :ref:`secure a notebook server <notebook_server_security>` and how to :ref:`run it on |
|
12 | :ref:`secure a notebook server <notebook_server_security>` and how to :ref:`run it on | |
13 | a public interface <notebook_public_server>`. |
|
13 | a public interface <notebook_public_server>`. | |
14 |
|
14 | |||
15 | .. _ZeroMQ: http://zeromq.org |
|
15 | .. _ZeroMQ: http://zeromq.org | |
16 |
|
16 | |||
17 | .. _Tornado: http://www.tornadoweb.org |
|
17 | .. _Tornado: http://www.tornadoweb.org | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | .. _notebook_server_security: |
|
20 | .. _notebook_server_security: | |
21 |
|
21 | |||
22 | Securing a notebook server |
|
22 | Securing a notebook server | |
23 | -------------------------- |
|
23 | -------------------------- | |
24 |
|
24 | |||
25 | You can protect your notebook server with a simple single password by |
|
25 | You can protect your notebook server with a simple single password by | |
26 | setting the :attr:`NotebookApp.password` configurable. You can prepare a |
|
26 | setting the :attr:`NotebookApp.password` configurable. You can prepare a | |
27 | hashed password using the function :func:`IPython.lib.security.passwd`: |
|
27 | hashed password using the function :func:`IPython.lib.security.passwd`: | |
28 |
|
28 | |||
29 | .. sourcecode:: ipython |
|
29 | .. sourcecode:: ipython | |
30 |
|
30 | |||
31 | In [1]: from IPython.lib import passwd |
|
31 | In [1]: from IPython.lib import passwd | |
32 | In [2]: passwd() |
|
32 | In [2]: passwd() | |
33 | Enter password: |
|
33 | Enter password: | |
34 | Verify password: |
|
34 | Verify password: | |
35 | Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' |
|
35 | Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' | |
36 |
|
36 | |||
37 | .. note:: |
|
37 | .. note:: | |
38 |
|
38 | |||
39 | :func:`~IPython.lib.security.passwd` can also take the password as a string |
|
39 | :func:`~IPython.lib.security.passwd` can also take the password as a string | |
40 | argument. **Do not** pass it as an argument inside an IPython session, as it |
|
40 | argument. **Do not** pass it as an argument inside an IPython session, as it | |
41 | will be saved in your input history. |
|
41 | will be saved in your input history. | |
42 |
|
42 | |||
43 | You can then add this to your :file:`ipython_notebook_config.py`, e.g.:: |
|
43 | You can then add this to your :file:`ipython_notebook_config.py`, e.g.:: | |
44 |
|
44 | |||
45 | # Password to use for web authentication |
|
45 | # Password to use for web authentication | |
46 | c = get_config() |
|
46 | c = get_config() | |
47 | c.NotebookApp.password = |
|
47 | c.NotebookApp.password = | |
48 | u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' |
|
48 | u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed' | |
49 |
|
49 | |||
50 | When using a password, it is a good idea to also use SSL, so that your |
|
50 | When using a password, it is a good idea to also use SSL, so that your | |
51 | password is not sent unencrypted by your browser. You can start the notebook |
|
51 | password is not sent unencrypted by your browser. You can start the notebook | |
52 | to communicate via a secure protocol mode using a self-signed certificate with |
|
52 | to communicate via a secure protocol mode using a self-signed certificate with | |
53 | the command:: |
|
53 | the command:: | |
54 |
|
54 | |||
55 | $ ipython notebook --certfile=mycert.pem |
|
55 | $ ipython notebook --certfile=mycert.pem | |
56 |
|
56 | |||
57 | .. note:: |
|
57 | .. note:: | |
58 |
|
58 | |||
59 | A self-signed certificate can be generated with ``openssl``. For example, |
|
59 | A self-signed certificate can be generated with ``openssl``. For example, | |
60 | the following command will create a certificate valid for 365 days with |
|
60 | the following command will create a certificate valid for 365 days with | |
61 | both the key and certificate data written to the same file:: |
|
61 | both the key and certificate data written to the same file:: | |
62 |
|
62 | |||
63 | $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem |
|
63 | $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem | |
64 |
|
64 | |||
65 | Your browser will warn you of a dangerous certificate because it is |
|
65 | Your browser will warn you of a dangerous certificate because it is | |
66 | self-signed. If you want to have a fully compliant certificate that will not |
|
66 | self-signed. If you want to have a fully compliant certificate that will not | |
67 | raise warnings, it is possible (but rather involved) to obtain one, |
|
67 | raise warnings, it is possible (but rather involved) to obtain one, | |
68 | as explained in detail in `this tutorial`__. |
|
68 | as explained in detail in `this tutorial`__. | |
69 |
|
69 | |||
70 | .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars |
|
70 | .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars | |
71 |
|
71 | |||
72 | Keep in mind that when you enable SSL support, you will need to access the |
|
72 | Keep in mind that when you enable SSL support, you will need to access the | |
73 | notebook server over ``https://``, not over plain ``http://``. The startup |
|
73 | notebook server over ``https://``, not over plain ``http://``. The startup | |
74 | message from the server prints this, but it is easy to overlook and think the |
|
74 | message from the server prints this, but it is easy to overlook and think the | |
75 | server is for some reason non-responsive. |
|
75 | server is for some reason non-responsive. | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | .. _notebook_public_server: |
|
78 | .. _notebook_public_server: | |
79 |
|
79 | |||
80 | Running a public notebook server |
|
80 | Running a public notebook server | |
81 | -------------------------------- |
|
81 | -------------------------------- | |
82 |
|
82 | |||
83 | If you want to access your notebook server remotely via a web browser, |
|
83 | If you want to access your notebook server remotely via a web browser, | |
84 | you can do the following. |
|
84 | you can do the following. | |
85 |
|
85 | |||
86 | Start by creating a certificate file and a hashed password, as explained |
|
86 | Start by creating a certificate file and a hashed password, as explained | |
87 | above. Then create a custom profile for the notebook, with the following |
|
87 | above. Then create a custom profile for the notebook, with the following | |
88 | command line, type:: |
|
88 | command line, type:: | |
89 |
|
89 | |||
90 | $ ipython profile create nbserver |
|
90 | $ ipython profile create nbserver | |
91 |
|
91 | |||
92 | In the profile directory just created, edit the file |
|
92 | In the profile directory just created, edit the file | |
93 | ``ipython_notebook_config.py``. By default, the file has all fields |
|
93 | ``ipython_notebook_config.py``. By default, the file has all fields | |
94 | commented; the minimum set you need to uncomment and edit is the following:: |
|
94 | commented; the minimum set you need to uncomment and edit is the following:: | |
95 |
|
95 | |||
96 | c = get_config() |
|
96 | c = get_config() | |
97 |
|
97 | |||
98 | # Kernel config |
|
|||
99 | c.IPKernelApp.pylab = 'inline' # if you want plotting support always |
|
|||
100 |
|
||||
101 | # Notebook config |
|
98 | # Notebook config | |
102 | c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem' |
|
99 | c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem' | |
103 | c.NotebookApp.ip = '*' |
|
100 | c.NotebookApp.ip = '*' | |
104 | c.NotebookApp.open_browser = False |
|
101 | c.NotebookApp.open_browser = False | |
105 | c.NotebookApp.password = u'sha1:bcd259ccf...[your hashed password here]' |
|
102 | c.NotebookApp.password = u'sha1:bcd259ccf...[your hashed password here]' | |
106 | # It is a good idea to put it on a known, fixed port |
|
103 | # It is a good idea to put it on a known, fixed port | |
107 | c.NotebookApp.port = 9999 |
|
104 | c.NotebookApp.port = 9999 | |
108 |
|
105 | |||
109 | You can then start the notebook and access it later by pointing your browser |
|
106 | You can then start the notebook and access it later by pointing your browser | |
110 | to ``https://your.host.com:9999`` with ``ipython notebook |
|
107 | to ``https://your.host.com:9999`` with ``ipython notebook | |
111 | --profile=nbserver``. |
|
108 | --profile=nbserver``. | |
112 |
|
109 | |||
113 | Running with a different URL prefix |
|
110 | Running with a different URL prefix | |
114 | ----------------------------------- |
|
111 | ----------------------------------- | |
115 |
|
112 | |||
116 | The notebook dashboard (the landing page with an overview |
|
113 | The notebook dashboard (the landing page with an overview | |
117 | of the notebooks in your working directory) typically lives at the URL |
|
114 | of the notebooks in your working directory) typically lives at the URL | |
118 | ``http://localhost:8888/``. If you prefer that it lives, together with the |
|
115 | ``http://localhost:8888/``. If you prefer that it lives, together with the | |
119 | rest of the notebook, under a sub-directory, |
|
116 | rest of the notebook, under a sub-directory, | |
120 | e.g. ``http://localhost:8888/ipython/``, you can do so with |
|
117 | e.g. ``http://localhost:8888/ipython/``, you can do so with | |
121 | configuration options like the following (see above for instructions about |
|
118 | configuration options like the following (see above for instructions about | |
122 | modifying ``ipython_notebook_config.py``):: |
|
119 | modifying ``ipython_notebook_config.py``):: | |
123 |
|
120 | |||
124 | c.NotebookApp.base_url = '/ipython/' |
|
121 | c.NotebookApp.base_url = '/ipython/' | |
125 | c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'} |
|
122 | c.NotebookApp.webapp_settings = {'static_url_prefix':'/ipython/static/'} | |
126 |
|
123 | |||
127 | Using a different notebook store |
|
124 | Using a different notebook store | |
128 | -------------------------------- |
|
125 | -------------------------------- | |
129 |
|
126 | |||
130 | By default, the notebook server stores the notebook documents that it saves as |
|
127 | By default, the notebook server stores the notebook documents that it saves as | |
131 | files in the working directory of the notebook server, also known as the |
|
128 | files in the working directory of the notebook server, also known as the | |
132 | ``notebook_dir``. This logic is implemented in the |
|
129 | ``notebook_dir``. This logic is implemented in the | |
133 | :class:`FileNotebookManager` class. However, the server can be configured to |
|
130 | :class:`FileNotebookManager` class. However, the server can be configured to | |
134 | use a different notebook manager class, which can |
|
131 | use a different notebook manager class, which can | |
135 | store the notebooks in a different format. |
|
132 | store the notebooks in a different format. | |
136 |
|
133 | |||
137 | The bookstore_ package currently allows users to store notebooks on Rackspace |
|
134 | The bookstore_ package currently allows users to store notebooks on Rackspace | |
138 | CloudFiles or OpenStack Swift based object stores. |
|
135 | CloudFiles or OpenStack Swift based object stores. | |
139 |
|
136 | |||
140 | Writing a notebook manager is as simple as extending the base class |
|
137 | Writing a notebook manager is as simple as extending the base class | |
141 | :class:`NotebookManager`. The simple_notebook_manager_ provides a great example |
|
138 | :class:`NotebookManager`. The simple_notebook_manager_ provides a great example | |
142 | of an in memory notebook manager, created solely for the purpose of |
|
139 | of an in memory notebook manager, created solely for the purpose of | |
143 | illustrating the notebook manager API. |
|
140 | illustrating the notebook manager API. | |
144 |
|
141 | |||
145 | .. _bookstore: https://github.com/rgbkrk/bookstore |
|
142 | .. _bookstore: https://github.com/rgbkrk/bookstore | |
146 |
|
143 | |||
147 | .. _simple_notebook_manager: https://github.com/khinsen/simple_notebook_manager |
|
144 | .. _simple_notebook_manager: https://github.com/khinsen/simple_notebook_manager | |
148 |
|
145 | |||
149 | Known issues |
|
146 | Known issues | |
150 | ------------ |
|
147 | ------------ | |
151 |
|
148 | |||
152 | When behind a proxy, especially if your system or browser is set to autodetect |
|
149 | When behind a proxy, especially if your system or browser is set to autodetect | |
153 | the proxy, the notebook web application might fail to connect to the server's |
|
150 | the proxy, the notebook web application might fail to connect to the server's | |
154 | websockets, and present you with a warning at startup. In this case, you need |
|
151 | websockets, and present you with a warning at startup. In this case, you need | |
155 | to configure your system not to use the proxy for the server's address. |
|
152 | to configure your system not to use the proxy for the server's address. | |
156 |
|
153 | |||
157 | For example, in Firefox, go to the Preferences panel, Advanced section, |
|
154 | For example, in Firefox, go to the Preferences panel, Advanced section, | |
158 | Network tab, click 'Settings...', and add the address of the notebook server |
|
155 | Network tab, click 'Settings...', and add the address of the notebook server | |
159 | to the 'No proxy for' field. |
|
156 | to the 'No proxy for' field. |
General Comments 0
You need to be logged in to leave comments.
Login now