Skip to main content

Future Grid API client

Project description

fgp-api-python

Python client for Future Grid Platform API

Work in progress! This is still under active design.

(dragons be here).

Installation

pip install fgp

On the command line

The module will install a command line wrapper, fgp which will allow you to perform common API operations on the command line.

 fgp --help                                                                                                                                               
2020-04-28 14:55:17,591 - fgp - INFO - Configured logger
Usage: fgp [OPTIONS] COMMAND [ARGS]...

Options:
  --api-url TEXT          Futuregrid API url
  --api-app TEXT          Futuregrid API application name
  --api-header-host TEXT  Host header for HTTP requests
  --help                  Show this message and exit.

Commands:
  extension
  relation
  store

Using environment variables

All parameters may be provided as environment variables, provided:

  • as all uppercase,
  • replace dash with underscore
  • prefix with FGP_

The following commands are both valid:

fgp --api-url http://localhost:18082 --api-app ada store --device-type meter --store-name meterPqStore get-first-last --device-name 9990000001_9880000001

and

export FGP_API_URL=http://localhost:18082
export FGP_API_APP=ada
fgp store --device-type meter --store-name meterPqStore get-first-last --device-name 9990000001_9880000001

In a Docker container

➜ docker run --net host --rm -it fgp-api-python --api-url http://localhost:18082 extension --device-type meter --extension-name meter_no get --device-name 9990000001_9880000001
2020-04-28 05:13:25,058 - fgp - INFO - Configured logger
2020-04-28 05:13:25.060 | DEBUG    | fgp.cli.extension.commands:get:32 - Fetching extension value for extension=meter_no device=9990000001_9880000001 at timestamp=None
{
  "deviceKey": {
    "id": "f674e867-e987-4373-a292-96ea7657ed87"
  },
  "meterNo": "9990000001",
  "timeKey": 1582820145000,
  "timeKeyAsDate": 1582820145000,
  "timestamp": 1582820145000
}

In your application

import fgp
import datetime

# Initialise the client with your server url and application name
client = fgp.ApiClient(
    url='http://localhost:8082', 
    application='myapp', 
    # Headers: optional, but useful if you're port forwarding to a kubernetes environment and need to use
    # a hostname to hit the correct ingress
    headers={
        'Host': 'api.some-environment.domain.com'    
    }
)

# Request data for a device
df = client.store.get_data(
    device_type='meter', 
    store_name='meterPqStore',
    date_from=datetime.datetime(year=2019, month=10, day=1),
    date_to=datetime.datetime(year=2019, month=10, day=2),
    fields=['voltageA', 'currentA'],
    devices=['9000000002_9000000002']
)

# Request extension for a device
result = client.extension.get_at(
    device_type='meter',
    device_name='9990000001_9880000001',
    extension_name='meter_no'
)

# Request a device relationship
result = client.relation.get_at(
    device_type='meter',
    device_name='9990000001_9880000001',
    relation_name='meter_transformer'
)

# Query some reference data
client.reference.query(
    reference_name='event_reference',
    query='eventState==NEW;nmi==9880000001',
    order_by="timeKey",
    limit=100,
    page=0
)

Planned

  • Update events

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

fgp-0.2.17.tar.gz (12.2 kB view details)

Uploaded Source

File details

Details for the file fgp-0.2.17.tar.gz.

File metadata

  • Download URL: fgp-0.2.17.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.11

File hashes

Hashes for fgp-0.2.17.tar.gz
Algorithm Hash digest
SHA256 46613f5ae6e4a04c91f5b200efa132f2504b4d14b4f175f9bad7bc0cb14a795e
MD5 8bb4352ef2f43129de4ef9b04ba6604f
BLAKE2b-256 b3561f407dc9b764fd2a80ff7de73bb74fb39bb76ef2ab4d1c50067531026813

See more details on using hashes here.

Supported by

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