Skip to main content

A connector to connect to the Lizard-API (https://demo.lizard.net/api/v2/) with Python.

Project description

lizard-connector

Introduction

Connector to Lizard api (e.g. https://demo.lizard.net/api/v2) for python.

Includes: - Datatypes (experimental / alpha) - Endpoint (Easy access to Lizard api endpoints) - Connector (http handling) - queryfunctions for special cases such as geographical queries and time related queries other queries can be input as a dictionary - parserfunctions to parse the json obtained from Endpoint queries

Example usage

Use one endpoints https://demo.lizard.net/api/v2 in Python with the Endpoint class:

import lizard_connector
import datetime

# Fill in your username and password
timeseries = lizard_connector.connector.Endpoint(
    username = "example.username",
    password = "example_password",
    endpoint = 'timeseries'
)

endpoint = 'timeseries'
south_west = [48.0, -6.8]
north_east = [56.2, 18.9]

organisation_id = 'example_organisation_uuid'

start = datetime.datetime(1970, 1, 1)
end = datetime.datetime.now()

relevant_queries = [
    lizard_connector.queries.in_bbox(south_west, north_east, endpoint),
    lizard_connector.queries.organisation(organisation_id, endpoint),
    lizard_connector.queries.datetime_limits(start, end)
]

results = timeseries.download(*relevant_queries)

Usage with PyQT (for Qgis plugins)

You can create a QThread worker like so:

from PyQt4.QtCore import QThread
from PyQt4.QtCore import pyqtSignal


class Worker(QThread):
    """This class creates a worker thread for getting the data."""
    output = pyqtSignal(object)

    def __init__(self, parent=None, endpoint=None, *querydicts, **queries):
        """Initiate the Worker."""
        super(Worker, self).__init__(parent)
        self._endpoint = endpoint
        self._querydicts = querydicts
        self._queries = queries

    def run(self):
        """Called indirectly by PyQt if you call start().
        This method retrieves the data from Lizard and emits it via the
        output signal as dictionary.
        """
        data = self._endpoint._synchronous_download_async(
            *self._querydicts, **self._queries)
        self.output.emit(data)

Credits

Changelog of lizard-connector

0.6 (2018-02-07)

  • Add explicit py2/3 imports to mitigate problems with the future library.

0.5 (2017-10-16)

  • Compatible with python 2.7.

  • Refactored pagination.

  • Added Async downloads with callback.

  • Removes max_result on Endpoint initialisation.

0.4 (2016-06-05)

  • Fixed bug in iteration over paginated results.

  • When all_pages is set to False all methods involving get return the object as an iterator.

0.3 (2016-05-06)

  • Http base urls are not allowed, throws exception when baseurl is not secure (i.e. does not start with https).

  • Fixed a bug that caused a get to run two times.

0.2 (2016-05-04)

  • Added Datatype classes.

  • Renamed Endpoint get and post to download and upload.

0.1 (2016-03-29)

  • Basic setup

  • Added tests

  • Initial project structure created with nensskel 1.37.dev0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lizard-connector-0.6.tar.gz (23.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page