jupyter-duckdb 0.3.3__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. jupyter-duckdb-0.4.1/PKG-INFO +198 -0
  2. jupyter-duckdb-0.4.1/README.md +184 -0
  3. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/setup.py +5 -4
  4. jupyter-duckdb-0.4.1/src/duckdb_kernel/__init__.py +1 -0
  5. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/src/duckdb_kernel/__main__.py +0 -0
  6. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/src/duckdb_kernel/kernel.json +0 -0
  7. jupyter-duckdb-0.4.1/src/duckdb_kernel/kernel.py +378 -0
  8. jupyter-duckdb-0.4.1/src/duckdb_kernel/magics/MagicCommand.py +63 -0
  9. jupyter-duckdb-0.4.1/src/duckdb_kernel/magics/MagicCommandCallback.py +21 -0
  10. jupyter-duckdb-0.4.1/src/duckdb_kernel/magics/MagicCommandException.py +2 -0
  11. jupyter-duckdb-0.4.1/src/duckdb_kernel/magics/MagicCommandHandler.py +71 -0
  12. jupyter-duckdb-0.4.1/src/duckdb_kernel/magics/__init__.py +4 -0
  13. jupyter-duckdb-0.4.1/src/duckdb_kernel/util/formatting.py +26 -0
  14. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/Column.py +18 -0
  15. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/Constraint.py +11 -0
  16. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/ForeignKey.py +15 -0
  17. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/Table.py +27 -0
  18. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/VizDrawer.py +219 -0
  19. jupyter-duckdb-0.4.1/src/duckdb_kernel/visualization/__init__.py +5 -0
  20. jupyter-duckdb-0.4.1/src/jupyter_duckdb.egg-info/PKG-INFO +198 -0
  21. jupyter-duckdb-0.4.1/src/jupyter_duckdb.egg-info/SOURCES.txt +24 -0
  22. jupyter-duckdb-0.4.1/src/jupyter_duckdb.egg-info/requires.txt +4 -0
  23. jupyter-duckdb-0.3.3/PKG-INFO +0 -15
  24. jupyter-duckdb-0.3.3/README.md +0 -1
  25. jupyter-duckdb-0.3.3/src/duckdb_kernel/kernel.py +0 -317
  26. jupyter-duckdb-0.3.3/src/jupyter_duckdb.egg-info/PKG-INFO +0 -15
  27. jupyter-duckdb-0.3.3/src/jupyter_duckdb.egg-info/SOURCES.txt +0 -11
  28. jupyter-duckdb-0.3.3/src/jupyter_duckdb.egg-info/requires.txt +0 -3
  29. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/setup.cfg +0 -0
  30. {jupyter-duckdb-0.3.3/src/duckdb_kernel → jupyter-duckdb-0.4.1/src/duckdb_kernel/util}/__init__.py +0 -0
  31. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/src/jupyter_duckdb.egg-info/dependency_links.txt +0 -0
  32. {jupyter-duckdb-0.3.3 → jupyter-duckdb-0.4.1}/src/jupyter_duckdb.egg-info/top_level.txt +0 -0
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.1
2
+ Name: jupyter-duckdb
3
+ Version: 0.4.1
4
+ Summary: a basic wrapper kernel for DuckDB
5
+ Home-page: https://github.com/erictroebs/jupyter-duckdb
6
+ Author: Eric Tröbs
7
+ Author-email: eric.troebs@tu-ilmenau.de
8
+ Project-URL: Bug Tracker, https://github.com/erictroebs/jupyter-duckdb/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+
15
+ # DuckDB Kernel for Jupyter
16
+
17
+ This is a simple DuckDB wrapper kernel which accepts SQL as input, executes it using a previously loaded DuckDB instance
18
+ and formats the output as a table. There are some magic commands that make teaching easier with this kernel.
19
+
20
+ ## Quick Start
21
+
22
+ [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fdbgit.prakinf.tu-ilmenau.de%2Fertr8623%2Fjupyter-duckdb.git/master)
23
+
24
+ ## Table of Contents
25
+
26
+ - [Setup](#setup)
27
+ - [Using pip](#using-pip)
28
+ - [Using Docker](#using-docker)
29
+ - [Usage](#usage)
30
+ - [A Note on Magic Commands](#a-note-on-magic-commands)
31
+ - [Load a Database](#load-a-database)
32
+ - [Schema Diagrams](#schema-diagrams)
33
+ - [Number of Rows](#number-of-rows)
34
+ - [Ship Tests With Your Notebook](#ship-tests-with-your-notebooks)
35
+
36
+ ## Setup
37
+
38
+ ### Using pip
39
+
40
+ Run `pip` to install the corresponding package from [pypi](https://pypi.org/project/jupyter-duckdb/) **after**
41
+ Jupyter is already installed.
42
+
43
+ ```bash
44
+ pip install jupyter-duckdb
45
+ ```
46
+
47
+ Register the kernel.
48
+
49
+ ```bash
50
+ jupyter kernelspec install <path to the site-packages directory>/duckdb_kernel
51
+ ```
52
+
53
+ Now start Jupyter the usual way and the kernel should be available.
54
+
55
+ ### Using Docker
56
+
57
+ Execute the following command to pull a and run a prepared image.
58
+
59
+ ```bash
60
+ docker run -p 8888:8888 troebs/jupyter:duckdb
61
+ ```
62
+
63
+ This image can also be used with JupyterHub and the
64
+ [DockerSpawner / SwarmSpawner](https://github.com/jupyterhub/dockerspawner)
65
+ and probably with the
66
+ [kubespawner](https://github.com/jupyterhub/kubespawner).
67
+ You can also build your own image using the [Dockerfile](Dockerfile) in the repository.
68
+
69
+ ## Usage
70
+
71
+ A detailed example can be found [in the repository](example/). The rest of this section describes the magic commands.
72
+
73
+ ### A Note on Magic Commands
74
+
75
+ Many Jupyter kernels make a difference between magic commands for a single line starting with one percent sign and
76
+ others for a whole cell starting with two percent signs. The upcoming magic commands always apply to a whole cell.
77
+ Therefore, it does not matter whether you use a single or two percent signs. However, the magic commands must always
78
+ be used at the beginning of a cell.
79
+
80
+ It is also possible to use more than one magic command per cell.
81
+
82
+ ### Load a Database
83
+
84
+ To load the database two magic commands are available.
85
+
86
+ `CREATE` creates a new database and therefore overwrites files with the same name without prompting. Using the optional
87
+ parameter `OF` you can either provide another DuckDB file or a file with SQL statements. In the first case the included
88
+ tables will be copied to the new database, while in the second case the SQL statements are just executed. We find this
89
+ feature very useful to work in a temporary copy of the data and therefore be able to restart at any time. The last
90
+ optional parameter `WITH_TESTS` is described in detail [below](#ship-tests-with-your-notebooks).
91
+
92
+ ```
93
+ %CREATE data.duckdb OF my_statements.sql
94
+ ```
95
+
96
+ `LOAD` on the other hand loads an existing database and returns an error if it does not exist. (That is why `OF` cannot
97
+ be used with `LOAD`! `WITH_TESTS` on the other hand is available also with this magic command.)
98
+
99
+ ```
100
+ %LOAD data.duckdb
101
+ ```
102
+
103
+ Only one database can be open at any time. If a new database is created or loaded, the current one is closed first and
104
+ saved to disk if necessary.
105
+
106
+ Please note that `:memory:` is also a valid file path for DuckDB. The data is then stored exclusively in the main
107
+ memory. In combination with `CREATE` and `OF` this makes it possible to work on a temporary copy in memory.
108
+
109
+ ### Schema Diagrams
110
+
111
+ The magic command `SCHEMA` can be used to create a simple schema diagram of the loaded database, showing all created
112
+ tables, their columns and data types, but without any views. Primary keys are printed in bold and unique keys are
113
+ underlined. Foreign keys are also highlighted and the dependencies between the tables are shown by arrows.
114
+
115
+ The optional parameter `LR` can be set to a true value to force a horizontal layout. This saves visual space especially
116
+ for larger amounts of tables.
117
+
118
+ ```
119
+ %SCHEMA LR 1
120
+ ```
121
+
122
+ ### Number of Rows
123
+
124
+ By default, only 20 rows are shown. All further lines are replaced by three dots. When hovering over the three dots
125
+ using the cursor, the number of omitted lines is displayed. Of course, the number of lines displayed can be changed.
126
+
127
+ The magic command `ALL_ROWS` and its short form `ALL` can be used to display **all** rows of the query in the same
128
+ cell. **Caution**: With large result sets this can lead to a frozen Jupyter instance.
129
+
130
+ ```sql
131
+ %ALL_ROWS
132
+ SELECT *
133
+ FROM foo
134
+ -- all rows
135
+ ```
136
+
137
+ The magic command `QUERY_MAX_ROWS` followed by an integer can be used to change the number of displayed rows for the
138
+ current cell.
139
+
140
+ ```sql
141
+ %QUERY_MAX_ROWS 50
142
+ SELECT *
143
+ FROM foo
144
+ -- 50 rows
145
+ ```
146
+
147
+ The magic command `MAX_ROWS` followed by an integer can be used to change the number of displayed rows for all future
148
+ queries including the current cell.
149
+
150
+ ```sql
151
+ %MAX_ROWS 30
152
+ SELECT *
153
+ FROM foo
154
+ -- 30 rows
155
+ ```
156
+
157
+ ```sql
158
+ SELECT *
159
+ FROM bar
160
+ -- 30 rows
161
+ ```
162
+
163
+ ### Ship Tests With Your Notebooks
164
+
165
+ Simple tests can be loaded together with the database with the help of the `WITH_TESTS` parameter. These tests are
166
+ stored as a JSON file. Each test is assigned a unique name, a result set and whether the test should check the order
167
+ of the result. A very simple test file looks like the following JSON object:
168
+
169
+ ```json
170
+ {
171
+ "task1": {
172
+ "ordered": false,
173
+ "equals": [
174
+ [
175
+ 1,
176
+ "Name 1"
177
+ ],
178
+ [
179
+ 2,
180
+ "Name 2"
181
+ ]
182
+ ]
183
+ }
184
+ }
185
+ ```
186
+
187
+ To bind a test to a cell, use the magic command `TEST` in combination with a name. After the cell is executed, the
188
+ result is evaluated and then displayed below the query result.
189
+
190
+ ```sql
191
+ %TEST task1
192
+ SELECT 2, 'Name 2'
193
+ UNION
194
+ SELECT 1, 'Name 1'
195
+ ```
196
+
197
+ Disclaimer: The integrated testing is work-in-progress and thus subject to potentially incompatible changes and
198
+ enhancements.
@@ -0,0 +1,184 @@
1
+ # DuckDB Kernel for Jupyter
2
+
3
+ This is a simple DuckDB wrapper kernel which accepts SQL as input, executes it using a previously loaded DuckDB instance
4
+ and formats the output as a table. There are some magic commands that make teaching easier with this kernel.
5
+
6
+ ## Quick Start
7
+
8
+ [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fdbgit.prakinf.tu-ilmenau.de%2Fertr8623%2Fjupyter-duckdb.git/master)
9
+
10
+ ## Table of Contents
11
+
12
+ - [Setup](#setup)
13
+ - [Using pip](#using-pip)
14
+ - [Using Docker](#using-docker)
15
+ - [Usage](#usage)
16
+ - [A Note on Magic Commands](#a-note-on-magic-commands)
17
+ - [Load a Database](#load-a-database)
18
+ - [Schema Diagrams](#schema-diagrams)
19
+ - [Number of Rows](#number-of-rows)
20
+ - [Ship Tests With Your Notebook](#ship-tests-with-your-notebooks)
21
+
22
+ ## Setup
23
+
24
+ ### Using pip
25
+
26
+ Run `pip` to install the corresponding package from [pypi](https://pypi.org/project/jupyter-duckdb/) **after**
27
+ Jupyter is already installed.
28
+
29
+ ```bash
30
+ pip install jupyter-duckdb
31
+ ```
32
+
33
+ Register the kernel.
34
+
35
+ ```bash
36
+ jupyter kernelspec install <path to the site-packages directory>/duckdb_kernel
37
+ ```
38
+
39
+ Now start Jupyter the usual way and the kernel should be available.
40
+
41
+ ### Using Docker
42
+
43
+ Execute the following command to pull a and run a prepared image.
44
+
45
+ ```bash
46
+ docker run -p 8888:8888 troebs/jupyter:duckdb
47
+ ```
48
+
49
+ This image can also be used with JupyterHub and the
50
+ [DockerSpawner / SwarmSpawner](https://github.com/jupyterhub/dockerspawner)
51
+ and probably with the
52
+ [kubespawner](https://github.com/jupyterhub/kubespawner).
53
+ You can also build your own image using the [Dockerfile](Dockerfile) in the repository.
54
+
55
+ ## Usage
56
+
57
+ A detailed example can be found [in the repository](example/). The rest of this section describes the magic commands.
58
+
59
+ ### A Note on Magic Commands
60
+
61
+ Many Jupyter kernels make a difference between magic commands for a single line starting with one percent sign and
62
+ others for a whole cell starting with two percent signs. The upcoming magic commands always apply to a whole cell.
63
+ Therefore, it does not matter whether you use a single or two percent signs. However, the magic commands must always
64
+ be used at the beginning of a cell.
65
+
66
+ It is also possible to use more than one magic command per cell.
67
+
68
+ ### Load a Database
69
+
70
+ To load the database two magic commands are available.
71
+
72
+ `CREATE` creates a new database and therefore overwrites files with the same name without prompting. Using the optional
73
+ parameter `OF` you can either provide another DuckDB file or a file with SQL statements. In the first case the included
74
+ tables will be copied to the new database, while in the second case the SQL statements are just executed. We find this
75
+ feature very useful to work in a temporary copy of the data and therefore be able to restart at any time. The last
76
+ optional parameter `WITH_TESTS` is described in detail [below](#ship-tests-with-your-notebooks).
77
+
78
+ ```
79
+ %CREATE data.duckdb OF my_statements.sql
80
+ ```
81
+
82
+ `LOAD` on the other hand loads an existing database and returns an error if it does not exist. (That is why `OF` cannot
83
+ be used with `LOAD`! `WITH_TESTS` on the other hand is available also with this magic command.)
84
+
85
+ ```
86
+ %LOAD data.duckdb
87
+ ```
88
+
89
+ Only one database can be open at any time. If a new database is created or loaded, the current one is closed first and
90
+ saved to disk if necessary.
91
+
92
+ Please note that `:memory:` is also a valid file path for DuckDB. The data is then stored exclusively in the main
93
+ memory. In combination with `CREATE` and `OF` this makes it possible to work on a temporary copy in memory.
94
+
95
+ ### Schema Diagrams
96
+
97
+ The magic command `SCHEMA` can be used to create a simple schema diagram of the loaded database, showing all created
98
+ tables, their columns and data types, but without any views. Primary keys are printed in bold and unique keys are
99
+ underlined. Foreign keys are also highlighted and the dependencies between the tables are shown by arrows.
100
+
101
+ The optional parameter `LR` can be set to a true value to force a horizontal layout. This saves visual space especially
102
+ for larger amounts of tables.
103
+
104
+ ```
105
+ %SCHEMA LR 1
106
+ ```
107
+
108
+ ### Number of Rows
109
+
110
+ By default, only 20 rows are shown. All further lines are replaced by three dots. When hovering over the three dots
111
+ using the cursor, the number of omitted lines is displayed. Of course, the number of lines displayed can be changed.
112
+
113
+ The magic command `ALL_ROWS` and its short form `ALL` can be used to display **all** rows of the query in the same
114
+ cell. **Caution**: With large result sets this can lead to a frozen Jupyter instance.
115
+
116
+ ```sql
117
+ %ALL_ROWS
118
+ SELECT *
119
+ FROM foo
120
+ -- all rows
121
+ ```
122
+
123
+ The magic command `QUERY_MAX_ROWS` followed by an integer can be used to change the number of displayed rows for the
124
+ current cell.
125
+
126
+ ```sql
127
+ %QUERY_MAX_ROWS 50
128
+ SELECT *
129
+ FROM foo
130
+ -- 50 rows
131
+ ```
132
+
133
+ The magic command `MAX_ROWS` followed by an integer can be used to change the number of displayed rows for all future
134
+ queries including the current cell.
135
+
136
+ ```sql
137
+ %MAX_ROWS 30
138
+ SELECT *
139
+ FROM foo
140
+ -- 30 rows
141
+ ```
142
+
143
+ ```sql
144
+ SELECT *
145
+ FROM bar
146
+ -- 30 rows
147
+ ```
148
+
149
+ ### Ship Tests With Your Notebooks
150
+
151
+ Simple tests can be loaded together with the database with the help of the `WITH_TESTS` parameter. These tests are
152
+ stored as a JSON file. Each test is assigned a unique name, a result set and whether the test should check the order
153
+ of the result. A very simple test file looks like the following JSON object:
154
+
155
+ ```json
156
+ {
157
+ "task1": {
158
+ "ordered": false,
159
+ "equals": [
160
+ [
161
+ 1,
162
+ "Name 1"
163
+ ],
164
+ [
165
+ 2,
166
+ "Name 2"
167
+ ]
168
+ ]
169
+ }
170
+ }
171
+ ```
172
+
173
+ To bind a test to a cell, use the magic command `TEST` in combination with a name. After the cell is executed, the
174
+ result is evaluated and then displayed below the query result.
175
+
176
+ ```sql
177
+ %TEST task1
178
+ SELECT 2, 'Name 2'
179
+ UNION
180
+ SELECT 1, 'Name 1'
181
+ ```
182
+
183
+ Disclaimer: The integrated testing is work-in-progress and thus subject to potentially incompatible changes and
184
+ enhancements.
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as file:
5
5
 
6
6
  setup(
7
7
  name='jupyter-duckdb',
8
- version='0.3.3',
8
+ version='0.4.1',
9
9
  author='Eric Tröbs',
10
10
  author_email='eric.troebs@tu-ilmenau.de',
11
11
  description='a basic wrapper kernel for DuckDB',
@@ -22,10 +22,11 @@ setup(
22
22
  ],
23
23
  package_dir={'': 'src'},
24
24
  packages=find_packages(where='src'),
25
- python_requires='>=3.6',
25
+ python_requires='>=3.7',
26
26
  install_requires=[
27
27
  'jupyter',
28
- 'duckdb==0.6.1',
28
+ 'duckdb==0.8.1',
29
+ 'graphviz==0.20.1',
29
30
  'checkmarkandcross'
30
31
  ],
31
32
  package_data={
@@ -33,5 +34,5 @@ setup(
33
34
  'kernel.json'
34
35
  ]
35
36
  },
36
- include_package_data=True,
37
+ include_package_data=True
37
38
  )
@@ -0,0 +1 @@
1
+ from .kernel import DuckDBKernel