Skip to main content

Python client for Hugr Arrow IPC over multipart/mixed

Project description

This is a python client for the Hugr IPC protocol

The client can request from the hugr and process them in a pythonic way. For the effective data transmission, the client uses the hugr ipc protocol to communicate with the server.

Installation

pip install hugr-client

or

uv pip install hugr-client

Usage

import hugr

# connect to the server
client = hugr.Client("http://localhost:15001/ipc")

# query data
data = client.query("""
    {
        devices {
            id
            name
            geom
            last_seen{
                time
                value
            }
        }
        drivers {
            id
            name
            devices {
                id
                name
                geom
                last_seen{
                    time
                    value
                }
            }
        }
        drivers_by_pk(id: "driver_id") {
            id
            name
            devices {
                id
                name
                geom
                last_seen{
                    time
                    value
                }
            }
        }
    }
""")

# get results as a pandas dataframe
df = data.df('data.devices') # or df = data["data.devices"].df()

# get results as a geopandas dataframe
gdf = data.gdf('data.devices', 'geom') # or gdf = data["data.devices"].gdf("geom")

# if the geometry field is placed in the nested object or arrays `gdf` will flatten the data until the geometry field is found
# field name is optional if data has only one geometry field
gdf = data.gdf('data.drivers', 'devices.geom') # or gdf = data["data.drivers"].gdf("devices.geom")

# get record as a dictionary
d = data.record('data.iot.drivers_by_pk')

# operate parts of results
part = data["data.devices"] 

# get pandas dataframe from the record
df = data.df('data.iot.drivers_by_pk') # or df = part.df()

# get geopandas dataframe from the record, dataframe will be flattened until the geometry field is found
gdf = data.gdf('data.iot.drivers_by_pk', 'devices.geom') # or gdf = part.gdf("devices.geom") or gdf = part.gdf() if only one geometry field is present

# explore geography data in the Jupyter Notebooks (labs or notebooks)

data.explore_map() # or part.explore_map() or hugr.explore_map(data) or hugr.explore_map(part)

Connection parameters

  • url - the url of the hugr server
  • api_key - the api key for the hugr server (if using api key authentication)
  • token - the token for the hugr server (if using token authentication)
  • role - the role for the hugr server (if user has a few roles in the token)

It also support querying by set up connection parameters.

Parameters will be passed from the environment variables:

  • HUGR_URL - the url of the hugr server
  • HUGR_API_KEY - the api key for the hugr server (if using api key authentication)
  • HUGR_TOKEN - the token for the hugr server (if using token authentication)
  • HUGR_API_KEY_HEADER - the header name for the api key (if using api key authentication)
  • HUGR_ROLE_HEADER - the header name for the role (if user has a few roles in the token).
import hugr

hugr.query(
    query="""
        {
            devices {
                id
                name
                geom
                last_seen{
                    time
                    value
                }
            }
        }
    """
)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome!

Dependencies

  • "requests",
  • "pyarrow",
  • "pandas",
  • "geopandas",
  • "shapely",
  • "requests_toolbelt",
  • "numpy",
  • "shapely",

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

hugr_client-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hugr_client-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file hugr_client-0.1.0.tar.gz.

File metadata

  • Download URL: hugr_client-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hugr_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f41929dd0fac0d2e2ff48aad0e0d7087934740dc4db737f8050be1230f87a973
MD5 ec190a5964551a87cd8b9eb1fbec51f6
BLAKE2b-256 f5ab99353299d14b4e3dac628521edf34daf90ca8fd5b3507d0db0871b827fe2

See more details on using hashes here.

File details

Details for the file hugr_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hugr_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hugr_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab56ce76708b4e906bd5ca0037c4f0bb73fe25162b390abc5470c2e27dbff9ce
MD5 cb74f9e665fea3d9765379f72572c4f0
BLAKE2b-256 1839dde259aaa6a75593f6d39efbd19d6821d7b3bab4a694d21bed6cd0de96ed

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