Skip to main content

Python SDK for interacting with the Evolve App Server

Project description

Evolve App Server Python Client

This library provides a wrapper to the Evolve App Server's API, allowing users of the Evolve SDK to authenticate with the Evolve App Server and upload studies.

Usage

from geojson import FeatureCollection
from src.zepben.eas import EasClient, StudyInput, StudyResultInput, GeoJsonOverlayInput, ResultSectionInput,
    SectionType, Mutation

eas_client = EasClient(
    host="<host>",
    port=1234,
    access_token="<access_token>",
    asynchronous=False,
)

eas_client.mutation(
    Mutation.add_studies(
        [
            StudyInput(
                name="<study name>",
                description="<study description>",
                tags=["<tag>", "<tag2>"],
                results=[
                    StudyResultInput(
                        name="<result_name>",
                        geoJsonOverlay=GeoJsonOverlayInput(
                            data=FeatureCollection(...),
                            styles=["style1"]
                        ),
                        sections=[
                            ResultSectionInput(
                                type=SectionType.TABLE,
                                name="<table name>",
                                description="<table description>",
                                columns=[
                                    {"key": "<column 1 key>", "name": "<column 1 name>"},
                                    {"key": "<column 2 key>", "name": "<column 2 name>"},
                                ],
                                data=[
                                    {"<column 1 key>": "<column 1 row 1 value>",
                                     "<column 2 key>": "<column 2 row 1 value>"},
                                    {"<column 1 key>": "<column 1 row 2 value>",
                                     "<column 2 key>": "<column 2 row 2 value>"}
                                ]
                            )
                        ]
                    )
                ],
                styles=[
                    {
                        "id": "style1",
                        # other Mapbox GL JS style properties
                    }
                ]
            )
        ]
    )
)

eas_client.close()

AsyncIO

The EasClient can operate in async mode if specified, like so:

from aiohttp import ClientSession
from geojson import FeatureCollection
from src.zepben.eas import EasClient, StudyInput, StudyResultInput, GeoJsonOverlayInput, ResultSectionInput,
    SectionType, Mutation


async def upload():
    eas_client = EasClient(
        host="<host>",
        port=1234,
        access_token="<access_token>",
        asynchronous=True,  # returns all methods as plain async methods
    )

    await eas_client.mutation(
        Mutation.add_studies(
            [
                StudyInput(
                    name="<study name>",
                    description="<study description>",
                    tags=["<tag>", "<tag2>"],
                    results=[
                        StudyResultInput(
                            name="<result_name>",
                            geoJsonOverlay=GeoJsonOverlayInput(
                                data=FeatureCollection(...),
                                styles=["style1"]
                            ),
                            sections=[
                                ResultSectionInput(
                                    type=SectionType.TABLE,
                                    name="<table name>",
                                    description="<table description>",
                                    columns=[
                                        {"key": "<column 1 key>", "name": "<column 1 name>"},
                                        {"key": "<column 2 key>", "name": "<column 2 name>"},
                                    ],
                                    data=[
                                        {"<column 1 key>": "<column 1 row 1 value>",
                                         "<column 2 key>": "<column 2 row 1 value>"},
                                        {"<column 1 key>": "<column 1 row 2 value>",
                                         "<column 2 key>": "<column 2 row 2 value>"}
                                    ]
                                )
                            ]
                        )
                    ],
                    styles=[
                        {
                            "id": "style1",
                            # other Mapbox GL JS style properties
                        }
                    ]
                )
            ]
        )
    )

    await eas_client.close()

I'm used to the old client, what do i do?

Migrating existing code

Most of the objects passed into requests are similar. The new EasClient is fully type hinted and self documenting.

For example.

from src.zepben.eas import EasClient, WorkPackageInput, HcExecutorConfigInput, FeederConfigsInput, FeederConfigInput

client = EasClient(host='host', port=1234)
client.get_work_package_cost_estimation(
    WorkPackageInput(
        feederConfigs=FeederConfigsInput(
            configs=[
                FeederConfigInput(
                    feeder='myFeeder',
                    years=[2024, 2025],
                    scenarios=['scenario1']
                )
            ]
        )
    )
)

Hovering over any kwarg or looking at any class definition will show all possible parameters, and their expected types.

Enabling legacy convenience methods

Legacy convenience methods can be enabled by passing enable_legacy_methods to __init__ of EasClient. eg:

from src.zepben.eas import EasClient

client = EasClient(enable_legacy_methods=True)

This will enable all deprecated and opt_in methods on the class, they are disabled by default.

Development

To regenerate the graphql client, run the following command

docker compose run codegen

If you have done any of the following, you will need to regenerate the docker image if testing locally.

  • Made changes to anything that affects the python package
  • Changed anything under ariadne_plugins
docker build .

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

zepben_eas-2.15.0b3.tar.gz (61.1 kB view details)

Uploaded Source

Built Distribution

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

zepben_eas-2.15.0b3-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file zepben_eas-2.15.0b3.tar.gz.

File metadata

  • Download URL: zepben_eas-2.15.0b3.tar.gz
  • Upload date:
  • Size: 61.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for zepben_eas-2.15.0b3.tar.gz
Algorithm Hash digest
SHA256 0c2a0cec8072a4febb37eacee70a5810d45c92e1c1c37d22f27377ddad5a603e
MD5 6784ef90e88d055276b66164296f63e3
BLAKE2b-256 f6fbd7c5b973329cb7c3f880747b0c77c551f7c4a7547dfdfa78008bd07cab44

See more details on using hashes here.

File details

Details for the file zepben_eas-2.15.0b3-py3-none-any.whl.

File metadata

  • Download URL: zepben_eas-2.15.0b3-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for zepben_eas-2.15.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 a5e4b9896e31fc9200e39704a03f4f93c930181024990136c8df8bb0a854d056
MD5 57f440c234d2667320cf088705b8852b
BLAKE2b-256 f07dbc1171b7a4aede05a5880c64be645ba24e4add18db98df226a92747d4f6d

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