Skip to main content

Devopness API Python SDK - Painless essential DevOps to everyone

Project description

Devopness SDK - Python

PyPI version

The official Devopness SDK for Python.

This SDK provides predefined classes to access Devopness platform resources. It's suitable for building CLI tools, backend services, or automation scripts, helping you interact with the Devopness API.

📌 Table of Contents

Usage

The SDK supports both asynchronous and synchronous usage, so you can choose based on your needs.

Install

Install the SDK using your preferred package manager:

# Using uv
uv add devopness

# Using poetry
poetry add devopness

# Using pip
pip install devopness

Initializing

Import the SDK and create an instance of DevopnessClient or DevopnessClientAsync:

from devopness import DevopnessClient, DevopnessClientAsync

devopness = DevopnessClient()
devopness_async = DevopnessClientAsync()

Custom Configuration

You can provide a custom configuration when initializing the client:

from devopness import DevopnessClient, DevopnessClientAsync, DevopnessClientConfig

config = DevopnessClientConfig(base_url='https://api.devopness.com', timeout=10)

devopness = DevopnessClient(config)
devopness_async = DevopnessClientAsync(config)

Configuration options:

Parameter Default Description
auto_refresh_token True Whether the access token is automatically refreshed
base_url https://api.devopness.com Base URL for all API requests
timeout 30 Timeout for HTTP requests (in seconds)
default_encoding utf-8 Encoding for response content

Authenticating

To authenticate, invoke the login_user method on the users service.

Asynchronous usage

import asyncio

from devopness import DevopnessClientAsync
from devopness.models import UserLogin

devopness = DevopnessClientAsync({'auto_refresh_token': False})

async def authenticate(user_email, user_pass):
    user_data = UserLogin(email=user_email, password=user_pass)
    user_tokens = await devopness.users.login_user(user_data)

    # The `access_token` must be set every time a token is obtained or refreshed,
    # if the `auto_refresh_token` option is set to `False`.
    devopness.access_token = user_tokens.data.access_token

if __name__ == "__main__":
    asyncio.run(authenticate('user@email.com', 'secret-password'))

Synchronous usage

from devopness import DevopnessClient
from devopness.models import UserLogin

devopness = DevopnessClient({'auto_refresh_token': False})

def authenticate(user_email, user_pass):
    user_data = UserLogin(email=user_email, password=user_pass)
    user_tokens = devopness.users.login_user(user_data)

    # The `access_token` must be set every time a token is obtained or refreshed,
    # if the `auto_refresh_token` option is set to `False`.
    devopness.access_token = user_tokens.data.access_token

if __name__ == "__main__":
    authenticate('user@email.com', 'secret-password')

Invoking authentication-protected endpoints

Once authenticated, you can invoke protected endpoints like retrieving user details.

Asynchronous usage

import asyncio

from devopness import DevopnessClientAsync
from devopness.models import UserLogin

devopness = DevopnessClientAsync()

async def authenticate(user_email, user_pass):
    user_data = UserLogin(email=user_email, password=user_pass)
    await devopness.users.login_user(user_data)

async def get_user_profile():
    await authenticate('user@email.com', 'secret-password')
    current_user = await devopness.users.get_user_me()
    print(f'User ID: {current_user.data.id}')

if __name__ == "__main__":
    asyncio.run(get_user_profile())

Synchronous usage

from devopness import DevopnessClient
from devopness.models import UserLogin

devopness = DevopnessClient()

def authenticate(user_email, user_pass):
    user_data = UserLogin(email=user_email, password=user_pass)
    devopness.users.login_user(user_data)

def get_user_profile():
    authenticate('user@email.com', 'secret-password')
    current_user = devopness.users.get_user_me()
    print(f'User ID: {current_user.data.id}')

if __name__ == "__main__":
    get_user_profile()

Error Handling

The SDK provides structured error handling through exceptions:

  • DevopnessApiError: This exception is raised when the Devopness API returns an error response. This typically indicates issues with the request itself, such as invalid input data, unauthorized access, or resource not found. It provides the following attributes to help diagnose the error:
Attribute Description
status_code The HTTP status code returned by the API
message A general error message from the API
errors An optional dictionary containing detailed validation errors, often encountered during create or update operations
  • DevopnessNetworkError: This exception is raised when a generic network-related issue occurs during the communication with the Devopness API. This could be due to problems like an unreachable host, connection timeouts, or other network configuration errors.

Both exceptions inherit from DevopnessSdkError, the base class for all SDK exceptions. You can use this class to catch and handle all exceptions raised by the SDK.

Development

To build the SDK locally, use Docker:

With Docker

Prerequisites

Steps

  1. Navigate to the project directory:
cd packages/sdks/python/
  1. Build the Docker image:
make build-image
  1. Build the Python SDK:
make build-sdk-python

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

devopness-1.3.7.tar.gz (117.5 kB view details)

Uploaded Source

Built Distribution

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

devopness-1.3.7-py3-none-any.whl (377.9 kB view details)

Uploaded Python 3

File details

Details for the file devopness-1.3.7.tar.gz.

File metadata

  • Download URL: devopness-1.3.7.tar.gz
  • Upload date:
  • Size: 117.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for devopness-1.3.7.tar.gz
Algorithm Hash digest
SHA256 ecadcc3ea2a6db079051de1c799286195273ada7eec6331983fa6f27d2a8c2aa
MD5 ea8aee020148229b5702600b1ddfeb5a
BLAKE2b-256 e009c1e18ef9415b824e6041bafbed4a9b3140f88d2efdc777ffc2e8dfa53352

See more details on using hashes here.

File details

Details for the file devopness-1.3.7-py3-none-any.whl.

File metadata

  • Download URL: devopness-1.3.7-py3-none-any.whl
  • Upload date:
  • Size: 377.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/6.11.0-1018-azure

File hashes

Hashes for devopness-1.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1433fc0384f2b711752d58c916d2e18de1c4ea10629d37716b2d38cdd4a0fb42
MD5 e67a406f9635bfed4702841cc88c5d81
BLAKE2b-256 c4439aee652c0ebada1aab634e04ab50372bf531e4d84710f31ee6a26af59c05

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