Skip to main content

Generate Lattice SDK for HTTP

This guide shows how to generate client SDKs for the Lattice SDK in HTTP with your preferred language.

Click to go to the HTTP SDK repository in GitHub. By downloading and/or using, you agree to the Terms & Conditions. If you do not agree, do not use the SDK.

Before you begin

Before you generate and use the HTTP SDK for a language of your choice, do the following:

  1. Complete the setup steps to generate a valid API token and publish at least one entity to your environment.
  2. Install the OpenAPI Generator. This package allows you to generate Lattice SDKs for HTTP for your preferred language. For more information about supported languages in OpenAPI, see the Overview on the OpenAPITools GitHub page.
note

Anduril is not affiliated with OpenAPI Tools.

Generate SDKs

To generate HTTP SDKs:

  1. In your terminal, clone the Lattice OpenAPI specification repo:

    git clone https://github.com/anduril/lattice-sdk-openapi.git lattice_sdk
    cd lattice_sdk
  2. From the root of your local repo, generate HTTP SDKs for your client by running the following commands:

    Requires: Python 3.8+

    openapi-generator generate \
    -i openapi/entities_openapi.pub.yaml \
    -g python \
    -o lattice_sdk_py/entities_api \
    --package-name=entities_api

    openapi-generator generate \
    -i openapi/tasks_openapi.pub.yaml \
    -g python \
    -o lattice_sdk_py/tasks_api \
    --package-name=tasks_api

    The output is stored in lattice_sdk/lattice_sdk_py. If you generate SDKs successfully, you should see the following files in your folder:

    • lattice_sdk_py/entities_api/entities_api/models/entity.py
    • lattice_sdk_py/tasks_api/tasks_api/models/task.py

    Install both packages to your Python environment:

    pip install lattice_sdk_py/entities_api
    pip install lattice_sdk_py/tasks_api

    Confirm packages were installed in a python shell:

    python
    import entities_api # successful if no returned error
    import tasks_api # successful if no returned error
    note

    You might see o.o.codegen.DefaultGenerator - X not generated errors. This won’t affect the majority of use cases.

Example request

Run the following example GetEntity request to verify your setup with the HTTP SDKs is complete:

Run the example in Python:

  1. Create a new file get_entity.py in the project directory, and add the following code:

    from entities_api import Configuration, ApiClient
    from entities_api.models import Entity
    from entities_api.api import EntityApi

    def get_entity(lattice_hostname: str, bearer_token: str, entity_id: str) -> Entity:
    config = Configuration(host=f"https://{lattice_hostname}/api/v1/")
    api_client = ApiClient(configuration=config, header_name="Authorization", header_value=f"Bearer {bearer_token}")
    entity_api = EntityApi(api_client=api_client)
    response = entity_api.get_entity_by_id(entity_id=entity_id)
    return response

    try:
    # Replace $YOUR_LATTICE_HOSTNAME and $YOUR_BEARER_TOKEN with your information.
    entity = get_entity("$YOUR_LATTICE_HOSTNAME", "$YOUR_BEARER_TOKEN", "example-entity-id")
    print(entity)
    except Exception as error:
    print(f"Lattice HTTP SDK GetEntity error {error}")

    Replace $YOUR_LATTICE_HOSTNAME and $YOUR_BEARER_TOKEN with your information. If you have the entity_id from the getting started example, replace example-entity-id.

  2. Run the example on the command line:

    python get_entity.py

If the request is successful and you specified a valid entity-id you should see the entity data. Alternatively, if you use example-entity-id, you get an expected 404 NOT_FOUND_ERROR. This means you successfully authenticated and completed the call to your environment, but the entity does not exist.

What's next