Skip to content

Commit 97acfa6

Browse files
author
Scott Sanderson
authored
Merge pull request #25 from quantopian/document-hybridmanager
DOC: Add an example for HybridContentsManager.
2 parents 369307f + ff2b86d commit 97acfa6

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

examples/hybrid_manager_example.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This example shows how to configure Jupyter/IPython to use the more complex
2+
# HybridContentsManager.
3+
4+
# A HybridContentsManager implements the contents API by delegating requests to
5+
# other contents managers. Each sub-manager is associated with a root
6+
# directory, and all requests for data within that directory are routed to the
7+
# sub-manager.
8+
9+
# A HybridContentsManager needs two pieces of information at configuration time:
10+
11+
# 1. ``manager_classes``, a map from root directory to the type of contents
12+
# manager to use for that root directory.
13+
# 2. ``manager_kwargs``, a map from root directory to a dict of keywords to
14+
# pass to the associated sub-manager.
15+
16+
from pgcontents.pgmanager import PostgresContentsManager
17+
from pgcontents.hybridmanager import HybridContentsManager
18+
19+
# Using Jupyter (IPython >= 4.0).
20+
# from notebook.services.contents.filemanager import FileContentsManager
21+
# Using Legacy IPython.
22+
from IPython.html.services.contents.filemanager import FileContentsManager
23+
24+
c = get_config()
25+
26+
c.NotebookApp.contents_manager_class = HybridContentsManager
27+
c.HybridContentsManager.manager_classes = {
28+
# Associate the root directory with a PostgresContentsManager.
29+
# This manager will receive all requests that don't fall under any of the
30+
# other managers.
31+
'': PostgresContentsManager,
32+
# Associate /directory with a FileContentsManager.
33+
'directory': FileContentsManager,
34+
# Associate /other_directory with another FileContentsManager.
35+
'other_directory': FileContentsManager,
36+
}
37+
c.HybridContentsManager.manager_kwargs = {
38+
# Args for root PostgresContentsManager.
39+
'': {
40+
'db_url': 'postgresql://ssanderson@/pgcontents_testing',
41+
'user_id': 'my_awesome_username',
42+
'max_file_size_bytes': 1000000, # Optional
43+
},
44+
# Args for the FileContentsManager mapped to /directory
45+
'directory': {
46+
'root_dir': '/home/ssanderson/some_local_directory',
47+
},
48+
# Args for the FileContentsManager mapped to /other_directory
49+
'other_directory': {
50+
'root_dir': '/home/ssanderson/some_other_local_directory',
51+
}
52+
}

0 commit comments

Comments
 (0)