Skip to main content

A client for the SpearheadOps GraphQL API

Project description

SpearheadClient

SpearheadClient is a type-safe Python SDK for interacting with your organization's SpearheadOps data using prepared calls via a GraphQL API. You can also write your own strongly-typed GraphQL queries using Pydantic models.

📦 Installation

Install the latest version using pip:

pip install spearheadclient

Client

The Client class provides methods for interacting with the Spearhead API. It requires an authenticated HTTP client to be initialized.

Initialization

The Client requires an authenticated HTTP client to be passed during initialization. The recommended way is to use the AuthInfinityHttpClient:

from SpearheadClient import Client
from SpearheadClient.AuthInfinity.AuthInfinityHttpClient import AuthInfinityHttpClient

# Initialize the HTTP client with your credentials
http_client = AuthInfinityHttpClient(
    access_key="your_access_key",
    secret_key="your_secret_key"
)

# Initialize the main client with the HTTP client
client = Client(http_client=http_client)

Authentication

The AuthInfinityHttpClient handles authentication automatically. It will:

  1. Authenticate using the provided access_key and secret_key
  2. Automatically refresh tokens when they expire
  3. Handle 401 unauthorized responses by re-authenticating
  4. Manage JWT tokens and their expiration

The client will automatically handle token refresh and re-authentication when needed, so you don't need to manage the authentication state manually.

Available Methods

The Client class provides the following methods:

work_site_search

Search for work sites with filtering and pagination.

results = await client.work_site_search(
    where={"deleted_at": {"_is_null": True}},
    query="search term",  # optional
    order_by=[{"created_at": "desc"}],  # optional
    limit=10,  # optional
    offset=0  # optional
)

for ws in results.work_sites:
  print(ws.title)

work_site_detail

Get detailed information about a specific work site.

work_site = await client.work_site_detail(
    work_site_id="uuid-of-work-site"
)

print(work_site.work_site.title)

work_site_ownership

Get ownership information for a work site.

results = await client.work_site_ownership(
    work_site_id="uuid-of-work-site"
)

for wso in results.work_site_owners:
    print(f"{wso.customer.title}: {wso.started_at} - {wso.ended_at}")

work_site_ticket_activity

Get ticket activity details for a work site.

results = await client.work_site_ticket_activity(
    work_site_id="c8ef0e2d-507d-489f-a83f-69460b68e77f"
)

for ta in results.work_site_tickets:
    print(f"{ta.ticket_id}: {ta.started_at} - {ta.ended_at}")

Sending a Custom Query

You can also define your own queries and mutations.

from SpearheadClient import execute_sync

def get_worksites_in_state(state: str):
    query = """
query WorkSitesInState($state: String!) {
  work_sites(state: {_eq_: $state}}) {
    title
    state
  }
}
"""
    variables = {"state": state}
    response = execute_sync(client, query, variables)
    return response["WorkSitesInState"]

🛡 License

MIT License. See LICENSE file for details.

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

spearheadclient-1.0.2.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

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

spearheadclient-1.0.2-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file spearheadclient-1.0.2.tar.gz.

File metadata

  • Download URL: spearheadclient-1.0.2.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for spearheadclient-1.0.2.tar.gz
Algorithm Hash digest
SHA256 883e9f03ceed4cac056700c820556293782cc4c3dbecf4d1b972224eb43106aa
MD5 3e2b14daf1abe0f17728ebb5f48f2a1e
BLAKE2b-256 683e76df130f726bc2028142128266623eff94b4b5b883e7dada5ff19cf0e9e3

See more details on using hashes here.

File details

Details for the file spearheadclient-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for spearheadclient-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d81221dde748c4700c10c5a0319c518c2d305358612b22f70867c26c199de5c4
MD5 59d9030309b1ed7f6a39e8ee66ddb55e
BLAKE2b-256 5c22807f7c9e82cdaea203f32364a331ce7ed39d9b9d5cfe784f50a06c13b0e5

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