Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opsduty_client-0.0.9.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

opsduty_client-0.0.9-py3-none-any.whl (72.0 kB view details)

Uploaded Python 3

File details

Details for the file opsduty_client-0.0.9.tar.gz.

File metadata

  • Download URL: opsduty_client-0.0.9.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.14.0-1017-azure

File hashes

Hashes for opsduty_client-0.0.9.tar.gz
Algorithm Hash digest
SHA256 713a1a2e912e43c5791615f264c23dfff78fb077a18c5fac6641b2ed9d96baad
MD5 22c5fa13df6a046f73d2f63ac6cb0b03
BLAKE2b-256 5e65741cce9bd98adc3c910f06ec960a58c3d8472e2999e3a2b74aa5db10c53b

See more details on using hashes here.

File details

Details for the file opsduty_client-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: opsduty_client-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 72.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.3 Linux/6.14.0-1017-azure

File hashes

Hashes for opsduty_client-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ece0454820c60f522205d09ae9e2e15ffd8b31ae944efcc0a40d9c9b645941d5
MD5 1733b2d765875041a459c14e9cfcf059
BLAKE2b-256 098c5f79a1bca53b96a43fa92068cf2372e0499238c4095ffd6aaca559f59c3f

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