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.3.tar.gz (37.5 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.3-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spearheadclient-1.0.3.tar.gz
Algorithm Hash digest
SHA256 803dc81d969ff4fd970a2cbae30e4f4c2b7af180b862525d1064e229df22c26e
MD5 f0552350afc9ea17b3a43111928172d3
BLAKE2b-256 d537d96f61960f1c5d6cda8717c7e9fd6b46bd563d36245f90d6dcf4f4121431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spearheadclient-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2f4e48d115c26725e64d217fd3ff947c5b329855774a4d8f12b62ad5481bd9de
MD5 945e1665c099451f0ce5006a4dca2a0a
BLAKE2b-256 b4b5ee58b1a62839e566d33a35f915d15042a66562bdf550a128e6a367facbc3

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