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 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:
- Authenticate using the provided access_key and secret_key
- Automatically refresh tokens when they expire
- Handle 401 unauthorized responses by re-authenticating
- 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.search_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_sites_by_pk.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.customers_xref_work_sites:
print(f"{wso.customer.title}: {wso.started_at} - {wso.ended_at}")
work_site_detail_ticket_activity
Get ticket activity details for a work site.
results = await client.work_site_detail_ticket_activity(
work_site_id="c8ef0e2d-507d-489f-a83f-69460b68e77f"
)
for ta in results.ticket_activity:
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spearheadclient-1.0.1.tar.gz.
File metadata
- Download URL: spearheadclient-1.0.1.tar.gz
- Upload date:
- Size: 69.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6b48d06a8fd386426146b681b3c28c0536975f37df47018be3c5cc22d15ec00
|
|
| MD5 |
b09df0b0eb2a2387bb527b1c388a2940
|
|
| BLAKE2b-256 |
898d81dcf7b3371c70e5cb2c2eda5b59b6ab8a09f653ab2b086d600832a4bbcc
|
File details
Details for the file spearheadclient-1.0.1-py3-none-any.whl.
File metadata
- Download URL: spearheadclient-1.0.1-py3-none-any.whl
- Upload date:
- Size: 73.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
208c8b50a23ebcd2eda087492459a1db691c6e9ab831f0ad43f1934ef4707648
|
|
| MD5 |
f5814142f931f57de3b3e7301dc5e4bc
|
|
| BLAKE2b-256 |
1015191d49e0562f28a2a83e3e2c536bf3c2f3674c78af192fd40df2ef6ca7f2
|