Skip to main content

Light: 'Resume application project app icon' Dark: 'Resume application project app icon'

Polypheny Extension for IPython

This IPython extension adds %poly magics for querying Polypheny using any of the supported query languages. This extension takes inspiration from the brilliant IPython SQL Extension.

Installation

Via PyPi

The recommended way to install the package is with pip:

pip install ipython-polypheny

From Source

If you do not want to use pip, you can download the code and build it manually.

  1. Download the source code.
  2. At the root directory, run python -m build. This will produce .tar.gz and .whl files in the dist/ folder.
  3. Install the package using: python -m pip install ./dist/.whl.

Usage

Activate the extension using:

%load_ext poly

You can utilize both line magics (%poly) and cell magics (%%poly). A command must always follow the magic keyword. For instance:

# Print help
%poly help

Commands requiring arguments should separate them using a colon (:):

# Specify the http-interface address of a running Polypheny instance.
%poly db: http://localhost:13137

The colon can also be replaced by a line break when using cell magics. This is the ideal syntax for querying the database, where the command specifies the query language:

%%poly sql
SELECT * FROM emps

The result is automatically printed as a nicely formatted table.

Interact with the retrieved data in multiple ways:

Storing the result in a variable:

result = _

# Or when using line magics (note the required colon that separates the query from the command):
result = %poly sql: SELECT * FROM emps

Additionally to the query language, a namespace can be specified. It is also possible to set flags. The -c flag deactivates the cache for this query:

%%poly mql mynamespace -c
db.emps.find({})

Working With the Result

The result object provides useful ways to work with the retrieved data.

result = %poly sql: SELECT * FROM emps

Getting the raw ResultSet:

result.result_set

The data can be accessed like a two-dimensional list:

# get the value of the element in the first row and second column
result[0][1]

Iterate over the rows as dicts:

for employee in result.dicts():
    print(employee['name'], employee['salary'])

Provided Pandas is installed, it is possible to transform the result into a DataFrame:

df = result.as_df()

Advanced Features

It is possible to expand variables defined in the local namespace into a query. For this to work, the --template (shorter: -t) flag must be set:

key = 'salary'
x = 10000

%% poly -t sql: SELECT * FROM emps WHERE ${key} > ${x}

# is equal to
%% poly sql: SELECT * FROM emps WHERE salary > 10000

Be careful to not accidentally inject unwanted queries, as the values are not escaped.

Data Types

Polypheny's data types are mapped to Python's as follows:

Type in Polypheny Type in Python
BIGINT, INTEGER, SMALLINT, TINYINT int
DECIMAL, DOUBLE, REAL float
BOOLEAN bool
DOCUMENT, JSON, NODE, PATH dict
ARRAY list

Other types are stored as str. Failed casting operations will also result in str. If the raw data as a nested list of str is required, one can get it from the ResultSet:

raw_data = result.result_set['data']

Limitations

Working with multimedia and other blob types is currently not supported. While it does not result in an error, only the identifier is stored, not the actual content.

Contributing

Thank you for considering contributing! We truly appreciate any effort, whether it's fixing bugs, improving documentation, or suggesting new features. Here's a guide to help streamline the process:

  1. Start by Forking: Begin by forking the repository. Once done, you can work on your changes and then submit them as a pull request.

  2. Development Guidelines: Before diving in, take a moment to explore our Documentation. Pay special attention to the 'For Developers' section — it offers insights on setup, code style, organization, and other valuable resources tailored for developers.

  3. Adherence to Code of Conduct: We are committed to fostering an open and welcoming environment. As such, we request all contributors to uphold the standards outlined in our code of conduct throughout their interactions related to the project.

  4. Setting up for Development:

    • Editable Installation: To see your code changes reflected in real-time, install the extension in an editable mode. Execute the following command from the root directory of the extension:

      python -m pip install -e .
      

      This allows any modifications in the codebase to be instantly visible post-reloading the extension.

    • Utilize Autoreload: For a smoother development experience, consider activating the autoreload extension. This tool automatically reloads the extension and incorporates the recent code changes:

      %load_ext autoreload
      %autoreload 2
      %load_ext poly
      

Thank you for your dedication and enthusiasm for enhancing the Polypheny ecosystem! We look forward to reviewing your valuable contributions.

License

The Apache 2.0 License

Metadata

Release files for ipython-polypheny 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipython-polypheny 0.1.3
File Size Uploaded
ipython_polypheny-0.1.3.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipython-polypheny 0.1.3
File Interpreter ABI Platform
ipython_polypheny-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / ipython_polypheny-0.1.3.tar.gz

Download URL ipython_polypheny-0.1.3.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1889fa95c56dc1946c2b630502ad361dacdd1e60b029d66bb8bc315e61cec127
BLAKE2b-256 checksum
How to use checksums
a56b5d7b2e3840f42357d3d823076eb2d659813160153ae5d0918af99b5b4b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / ipython_polypheny-0.1.3-py3-none-any.whl

Download URL ipython_polypheny-0.1.3-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b038bf8c1a5d7d65e39bc5c79030024edaddf1be7c5a39d3f322cb380a71b72
BLAKE2b-256 checksum
How to use checksums
4cf432c5ff85a61f48aa3253d1413c902f288937f436ca0b39527627bc7333f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page