Devopness API Python SDK - Painless essential DevOps to everyone
Project description
Devopness SDK - Python
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
- Devopness SDK - Python
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 |
|---|---|---|
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 |
Authentication
Authentication with Personal Access Token
Ensure you have a Personal Access Token from Devopness. If you don't have one, see Add a Personal Access Token.
Asynchronous usage
import asyncio
from devopness import DevopnessClientAsync, DevopnessClientConfig
# Option 1: Pass token during initialization
config = DevopnessClientConfig(api_token='your-personal-access-token-here')
devopness = DevopnessClientAsync(config)
# Option 2: Set token after initialization
devopness = DevopnessClientAsync()
devopness.api_token = 'your-personal-access-token-here'
async def main():
current_user = await devopness.users.get_user_me()
print(f'User ID: {current_user.data.id}')
if __name__ == "__main__":
asyncio.run(main())
Synchronous usage
from devopness import DevopnessClient, DevopnessClientConfig
# Option 1: Pass token during initialization
config = DevopnessClientConfig(api_token='your-personal-access-token-here')
devopness = DevopnessClient(config)
# Option 2: Set token after initialization
devopness = DevopnessClient()
devopness.api_token = 'your-personal-access-token-here'
def main():
current_user = devopness.users.get_user_me()
print(f'User ID: {current_user.data.id}')
if __name__ == "__main__":
main()
Authentication with Project API Token
Ensure you have a Project API Token from Devopness. If you don't have one, see Add a Project API Token.
Asynchronous usage
import asyncio
from devopness import DevopnessClientAsync
devopness = DevopnessClientAsync()
devopness.api_token = 'your-project-api-token-here'
async def main():
project = await devopness.projects.get_project(project_id=123)
print(f'Project name: {project.data.name}')
if __name__ == "__main__":
asyncio.run(main())
Synchronous usage
from devopness import DevopnessClient
devopness = DevopnessClient()
devopness.api_token = 'your-project-api-token-here'
def main():
project = devopness.projects.get_project(project_id=123)
print(f'Project name: {project.data.name}')
if __name__ == "__main__":
main()
Authentication with Login (Deprecated)
Warning: Email/password authentication is no longer supported. API requests using this method return 4xx errors.
Invoking authentication-protected endpoints
Once authenticated, you can invoke protected endpoints. Here's an example of retrieving user details and listing projects:
Asynchronous usage
import asyncio
import os
from devopness import DevopnessClientAsync, DevopnessClientConfig
from devopness.core import DevopnessSdkError
config = DevopnessClientConfig(api_token=os.getenv('DEVOPNESS_API_TOKEN'))
devopness = DevopnessClientAsync(config)
async def get_user_profile():
try:
# Retrieve current user details
current_user = await devopness.users.get_user_me()
print(f'User ID: {current_user.data.id}')
except DevopnessSdkError as error:
print(f'Error: {error}')
if __name__ == "__main__":
asyncio.run(get_user_profile())
Synchronous usage
import os
from devopness import DevopnessClient, DevopnessClientConfig
from devopness.core import DevopnessSdkError
config = DevopnessClientConfig(api_token=os.getenv('DEVOPNESS_API_TOKEN'))
devopness = DevopnessClient(config)
def get_user_profile():
try:
# Retrieve current user details
current_user = devopness.users.get_user_me()
print(f'User ID: {current_user.data.id}')
except DevopnessSdkError as error:
print(f'Error: {error}')
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
- Navigate to the project directory:
cd packages/sdks/python/
- Build the Docker image:
make build-image
- Build the Python SDK:
make build-sdk-python
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 devopness-2.2.1.tar.gz.
File metadata
- Download URL: devopness-2.2.1.tar.gz
- Upload date:
- Size: 119.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66f7fa64dd637b13fc8c0c6b459449944b17bca12ffc7c5ad8485201e30e3fe5
|
|
| MD5 |
ede8bb43ff5ecc89000bae7eac070774
|
|
| BLAKE2b-256 |
cb2c5ec02d6fa44914a7d811fc2c2f1c0a88b4ba7c596d34f77f3975cdd28ac4
|
Provenance
The following attestation bundles were made for devopness-2.2.1.tar.gz:
Publisher:
release-packages.yml on devopness/devopness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
devopness-2.2.1.tar.gz -
Subject digest:
66f7fa64dd637b13fc8c0c6b459449944b17bca12ffc7c5ad8485201e30e3fe5 - Sigstore transparency entry: 1012125168
- Sigstore integration time:
-
Permalink:
devopness/devopness@048ddf7f758edd0c0f7de95370ed2b6d21d9d067 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/devopness
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-packages.yml@048ddf7f758edd0c0f7de95370ed2b6d21d9d067 -
Trigger Event:
push
-
Statement type:
File details
Details for the file devopness-2.2.1-py3-none-any.whl.
File metadata
- Download URL: devopness-2.2.1-py3-none-any.whl
- Upload date:
- Size: 383.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8427daf06e216e6db313c7dd1767f9bd026bad976c8abd9ec4c32876a2238a8e
|
|
| MD5 |
4bebcddf637cfff4f79bd6cf3f4ae4c2
|
|
| BLAKE2b-256 |
83790f68b3f36b6d45defbc9d3169ef46189928510c0beb6576665cbd056dd41
|
Provenance
The following attestation bundles were made for devopness-2.2.1-py3-none-any.whl:
Publisher:
release-packages.yml on devopness/devopness
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
devopness-2.2.1-py3-none-any.whl -
Subject digest:
8427daf06e216e6db313c7dd1767f9bd026bad976c8abd9ec4c32876a2238a8e - Sigstore transparency entry: 1012125206
- Sigstore integration time:
-
Permalink:
devopness/devopness@048ddf7f758edd0c0f7de95370ed2b6d21d9d067 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/devopness
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-packages.yml@048ddf7f758edd0c0f7de95370ed2b6d21d9d067 -
Trigger Event:
push
-
Statement type: