Skip to main content

Python client for managing AWX automation platform

Project description

🤖 PyAWX

Python client for managing AWX automation platform.

📌 Table of Contents

✨ Features

  • Authentication support: Built-in support for Basic Auth and OAuth2.
  • Data validation: Pydantic models ensure that payloads conform to the AWX API's expected structure.
  • Extensibility: Easily extendable to support new AWX resources or custom workflows.

📚 Documentation

Each module is documented in detail and can be explored using pdoc. Below is an overview of the key modules:

  • pyawx.auth: Authentication classes for Basic Auth and OAuth2.
  • pyawx.http: HTTP client abstraction for handling API requests.
  • pyawx.models: Pydantic models for data validation and serialization.
  • pyawx.resources: Resource classes for interacting with AWX resources.
  • pyawx.client: Client interface for interacting with the AWX API.

📦 Installation

work in progress

📖 Usage

🔒 Authentication

To interact with the AWX API, you need to authenticate using either Basic Authentication or OAuth2. Here's how to set up both methods:

🔑 Basic Authentication

from pyawxapi.client import Client

# Initialize the client with Basic Authentication
client = Client(
    "https://api.example.com",
    username="your_username",
    password="your_password",
)

# Fetch a job template by name
job_template = client.job_template.fetch("My Job Template")

🔑 OAuth2 Authentication

from pyawxapi.client import Client

# Initialize the client with OAuth2 Authentication
client = Client("https://api.example.com", token="your_oauth2_token")

# Fetch a workflow job template by name
workflow_job_template = client.workflow_job_template.fetch("My Workflow Job Template")

🔄 Working with Resources

The library provides resource-specific classes to interact with different AWX API endpoints. Below are examples of how to work with job templates and workflow job templates.

📜 Job Templates

from pyawxapi.models import JobTemplateModel

# Create a new job template
new_job_template = JobTemplateModel(
    name="My New Job",
    inventory="inventory_1",
    project="project_1",
    playbook="deploy.yml"
)

created_job_template = client.job_template.create(new_job_template)

# Update an existing job template
updated_job_template = JobTemplateModel(
    name="Updated Job Template",
    inventory="inventory_1",
    project="project_1",
    playbook="deploy.yml"
)

client.job_template.update("My Job Template", updated_job_template)

# Delete a job template
client.job_template.delete("My Job Template")

📜 Workflow Job Templates

from pyawxapi.models import WorkflowJobTemplateModel

# Create a new workflow job template
new_workflow = WorkflowJobTemplateModel(
    name="Release Deployment Workflow",
    inventory="prod_inventory",
    extra_vars='{"version": "1.2.3"}'
)
created_workflow = client.workflow_job_template.create(new_workflow)
print(created_workflow)

# Update an existing workflow job template
updated_workflow = WorkflowJobTemplateModel(
    name="Updated Workflow",
    inventory="prod_inventory",
    extra_vars='{"version": "1.2.4"}'
)
client.workflow_job_template.update("Release Deployment Workflow", updated_workflow)

# Delete a workflow job template
client.workflow_job_template.delete("Release Deployment Workflow")

✔️ Data Validation with Pydantic Models

The library uses Pydantic models to ensure that the data conforms to the AWX API's expected structure. This helps in reducing runtime errors by validating the data before sending it to the API.

from pydantic import ValidationError

from pyawxapi.models import JobTemplateModel

# Create a job template with validation
try:
    job_template = JobTemplateModel(
        name="Valid Job Template",
        inventory="inventory_1",
        project="project_1",
        playbook="deploy.yml",
    )
    print("Job template is valid:", job_template)
except ValidationError as e:
    print("Validation error:", e)

🤝 Contributing

work in progress

🧪 Testing

Run unit tests using pytest:

uv run pytest tests

🛠️ Roadmap

work in progress

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

pyawx-0.1.1.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

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

pyawx-0.1.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file pyawx-0.1.1.tar.gz.

File metadata

  • Download URL: pyawx-0.1.1.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.6

File hashes

Hashes for pyawx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bc0e703fcfb44afb52841dec450cdde9e38982bee8da89d4d8d0e55638d31041
MD5 c81b8052bc223b809a1d7465dfb4c526
BLAKE2b-256 f901ca6fdfc835cf026164f5ed6fad414929d7140a3b3542833ab0b9d2de98b1

See more details on using hashes here.

File details

Details for the file pyawx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyawx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.6

File hashes

Hashes for pyawx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc84e67302c88bb18a861de47874b75a7d6c29d322782674c31a7bac73381301
MD5 253a3b98607a031dbb61c60cb00baca2
BLAKE2b-256 f6160f0511e0b388e6930e0edb7ff9e2e58fda59af4a9f1a6f71729e2c383f86

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