Skip to main content

rasdapy - Talk rasql using Python

rasdapy is a client API for rasdaman that enables building and executing rasql queries within python.

Requirements

Installation

  1. Make sure you have installed pip3 (e.g. sudo apt install python-pip3)

  2. Install rasdapy3 with pip3 install rasdapy3

  1. Note that if you do not have setuptools, numpy, grpcio, and protobuf installed, they will be downloaded as dependencies.

Usage

A full client with a similar interface as the C++ rasql client is available that demonstrates how to use rasdapy to send queries to rasdaman and handle the results. Below the most important details for using rasdapy are listed.

Import rasdapy core API

>>> from rasdapy.db_connector import DBConnector
>>> from rasdapy.query_executor import QueryExecutor

Connect to rasdaman

The DBConnector maintains the connection to rasdaman. In order to connect it is necessary to specify the host and port on which rasmgr is running, as well as valid rasdaman username and password.

>>> db_connector = DBConnector("localhost", 7001, "rasadmin", "rasadmin")

Create the query executor

QueryExcutor is the interface through which rasql queries (create, insert, update, delete, etc.) are executed.

>>> query_executor = QueryExecutor(db_connector)

Open the connection to rasdaman

>>> db_connector.open()

Execute sample queries

The query below returns a list of all the collections available in rasdaman.

>>> colls = query_executor.execute_read("select c from RAS_COLLECTIONNAMES as c")
>>> print(colls)

Calculate the average of all values in collection mr2.

>>> result = query_executor.execute_read("select avg_cells(c) from mr2 as c")
>>> type(result)

Depending on the query the result will have a different type (e.g. scalar value, interval, array). Each data type is wrapped in a corresponding class.

Select a particular subset of each array in collection mr2. This query will return raw array data that can be converted to a Numpy ndarray.

>>> result = query_executor.execute_read("select m[0:10 ,0:10] from mr2 as m")
>>> numpy_array = result.to_array()

Encode array subset to PNG format and write the result to a file.

>>> result = query_executor.execute_read("select encode(m[0:10 ,0:10], \"png\") from mr2 as m")
>>> with open("/tmp/output.png", "wb") as binary_file:
>>>   binary_file.write(result.data[0])

Create a rasdaman collection. Note that you should be connected with a user that has write permission; by default this is rasadmin/rasadmin in rasdaman, but this can be managed by the administrator.

>>> query_executor.execute_write("create collection test_rasdapy GreySet")

Insert data from a PNG image into the collection. Similarly you need to have write permissions for this operation.

>>> query_executor.execute_write("insert into test_rasdapy values decode($1)", "mr_1.png")

Alternatively, you can import data from a raw binary file; in this case it is necessary to specify the spatial domain and array type.

>>> query_executor.execute_update_from_file("insert into test_rasdapy values $1",
                                            "raw_array.bin", "[0:100]", "GreyString")

Further example queries and a general guide for rasql can be found in the rasdaman documentation.

Close the connection to rasdaman

>>> db_connector.close()

Best practices:

It is recommended to follow this template in order to avoid problems with leaked transactions:

from rasdapy.db_connector import DBConnector
from rasdapy.query_executor import QueryExecutor

db_connector = DBConnector("localhost", 7001, "rasadmin", "rasadmin")
query_executor = QueryExecutor(db_connector)

db_connector.open()

try:
    query_executor.execute_read("...")
    query_executor.execute_write("...")
    # ... more Python code
finally:
    db_connector.close()

Contributors

  • Bang Pham Huu

  • Siddharth Shukla

  • Dimitar Misev

  • Jean-François Lecomte

  • Dragi Kamov

Thanks also to

  • Alex Mircea Dumitru

  • Vlad Merticariu

  • George Merticariu

  • Alex Toader

  • Peter Baumann

Metadata

Release files for rasdapy3 1.1.0

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

Source distribution (sdist)

Source distribution for rasdapy3 1.1.0
File Size Uploaded
rasdapy3-1.1.0.tar.gz 68.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rasdapy3 1.1.0
File Interpreter ABI Platform
rasdapy3-1.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 150.5 kB

Release files / rasdapy3-1.1.0.tar.gz

Download URL rasdapy3-1.1.0.tar.gz
Size 68.4 kB
Tags Source
SHA-256 checksum
How to use checksums
90cc70f3c5741a9ccf94d5b42f6cd069f290555c9fe34e3a0b278a05e924d36e
BLAKE2b-256 checksum
How to use checksums
ef5ae79ad7d19216d637bf3e403f1c34fe55e16f1bf0a3f60a59e2e83cde9869
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / rasdapy3-1.1.0-py2.py3-none-any.whl

Download URL rasdapy3-1.1.0-py2.py3-none-any.whl
Size 82.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5c4719646e0794c29488c80e61c15e2ab2d6a74f034baeab49f0bd29fcbec7f9
BLAKE2b-256 checksum
How to use checksums
7c8e848d2b8c14352d62a176d4820a594ee064008d01255233fdbc106b543c8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.5

1 release file

1.0.4

1 release file

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

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