|
| 1 | +StackqlMagic Extension for Jupyter |
| 2 | +================================== |
| 3 | + |
| 4 | +The ``StackqlMagic`` extension for Jupyter notebooks provides a convenient interface to run SQL queries against the StackQL database directly from within the notebook environment. Results can be visualized in a tabular format using Pandas DataFrames. |
| 5 | + |
| 6 | +Setup |
| 7 | +----- |
| 8 | + |
| 9 | +To enable the `StackqlMagic` extension in your Jupyter notebook, use the following command: |
| 10 | + |
| 11 | +.. code-block:: python |
| 12 | +
|
| 13 | + %load_ext pystackql |
| 14 | +
|
| 15 | +Usage |
| 16 | +----- |
| 17 | + |
| 18 | +The extension provides both line and cell magic functionalities: |
| 19 | + |
| 20 | +1. **Line Magic**: |
| 21 | + |
| 22 | + You can run StackQL queries directly from a single line: |
| 23 | + |
| 24 | + .. code-block:: python |
| 25 | +
|
| 26 | + %stackql DESCRIBE aws.ec2.instances |
| 27 | +
|
| 28 | +2. **Cell Magic**: |
| 29 | + |
| 30 | + For multi-line queries or when you need to use specific options: |
| 31 | + |
| 32 | + .. code-block:: python |
| 33 | +
|
| 34 | + %%stackql |
| 35 | + SELECT instanceType, COUNT(*) as num_instances |
| 36 | + FROM aws.ec2.instances |
| 37 | + WHERE region = '$region' GROUP BY instanceType |
| 38 | +
|
| 39 | +Options |
| 40 | +------- |
| 41 | + |
| 42 | +When using `StackqlMagic` as cell magic, you can pass in the following options: |
| 43 | + |
| 44 | +- **--no-display** : Suppresses the display of the results. Even when this option is enabled, the results are still saved in the `stackql_df` Pandas DataFrame. |
| 45 | + |
| 46 | +Example: |
| 47 | + |
| 48 | +.. code-block:: python |
| 49 | +
|
| 50 | + project = 'stackql-demo' |
| 51 | + zone = 'australia-southeast1-a' |
| 52 | + region = 'australia-southeast1' |
| 53 | +
|
| 54 | +.. code-block:: python |
| 55 | +
|
| 56 | + %%stackql --no-display |
| 57 | + SELECT name, status |
| 58 | + FROM google.compute.instances |
| 59 | + WHERE project = '$project' AND zone = '$zone' |
| 60 | +
|
| 61 | +This will run the query but won't display the results in the notebook. Instead, you can later access the results via the `stackql_df` variable. |
| 62 | + |
| 63 | +.. note:: |
| 64 | + |
| 65 | + The results of the queries are always saved in a Pandas DataFrame named `stackql_df` in the notebook's current namespace. This allows you to further process or visualize the data as needed. |
| 66 | + |
| 67 | +-------- |
| 68 | + |
| 69 | +This documentation provides a basic overview and usage guide for the `StackqlMagic` extension. For advanced usage or any additional features provided by the extension, refer to the source code or any other accompanying documentation. |
0 commit comments