A client library for accessing opsduty
Project description
opsduty-client
A client library for accessing opsduty
Usage
First, create a client:
from opsduty_client import Client
client = Client(base_url="https://opsduty.io")
If the endpoints you're going to hit require authentication, use AuthenticatedClient
instead:
from opsduty_client import AuthenticatedClient
client = AuthenticatedClient(base_url="https://opsduty.io", token="oAuth2 access token")
Now call your endpoint and use your models:
from opsduty_client.models import MyDataModel
from opsduty_client.api.my_tag import get_my_data_model
from opsduty_client.types import Response
with client as client:
my_data: MyDataModel = get_my_data_model.sync(client=client)
# or if you need more info (e.g. status_code)
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
Or do the same thing with an async version:
from opsduty_client.models import MyDataModel
from opsduty_client.api.my_tag import get_my_data_model
from opsduty_client.types import Response
async with client as client:
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
Advanced customizations
There are more settings on the generated Client
class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying httpx.Client
or httpx.AsyncClient
(depending on your use-case):
from opsduty_client import Client
def log_request(request):
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
def log_response(response):
request = response.request
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
client = Client(
base_url="https://opsduty.io",
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)
# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
import httpx
from opsduty_client import Client
client = Client(
base_url="https://opsduty.io",
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url="https://opsduty.io", proxies="http://localhost:8030"))
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
File details
Details for the file opsduty_client-0.0.3a1.tar.gz
.
File metadata
- Download URL: opsduty_client-0.0.3a1.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 850c5caca2dfab9611ee5482c401c811fbcfcbfee6a902006fdb99103254c75e |
|
MD5 | 2473a1b854436e25d88058c8f9d27265 |
|
BLAKE2b-256 | 946c1a9fb8502c701af9262f71c5fb37e414d474c933659b07ef6e3c5b6a3a68 |
File details
Details for the file opsduty_client-0.0.3a1-py3-none-any.whl
.
File metadata
- Download URL: opsduty_client-0.0.3a1-py3-none-any.whl
- Upload date:
- Size: 63.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ee3b91dabb6956b11f257253fce5abdbd50fdedeb184119c0b90fd08d2c027b |
|
MD5 | 688806a7fd64a9b4a848215364d9e6de |
|
BLAKE2b-256 | 0f08d8c6d9f5145e1cfa46301b2033d8466eceb9a05c17acedc5b3c1ad949891 |