Skip to main content

Python client for managing AWX automation platform

Project description

🤖 PyAWX

PyPI - Version GitHub License

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

📥 Pip

Install the pyawx package using pip:

pip install pyawx

📥 UV

Install the pyawx package using uv:

uv add pyawx

📖 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 pyawx import Client

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

# Check if the client is authenticated
if not client.is_authenticated():
    raise ValueError("Authentication failed: Invalid credentials")

🔑 OAuth2 Authentication

from pyawx import Client

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

🔄 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.

[!NOTE] 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.

📜 Job Templates

from pyawx.models import JobTemplateModel

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

# Create a new job template
new_job_template = JobTemplateModel(
    name="My New Job",
    inventory="inventory_1",
    project="project_1",
    playbook="deploy.yml"
)
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 pyawx.models import WorkflowJobTemplateModel

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

# Create a new workflow job template
new_workflow = WorkflowJobTemplateModel(
    name="Release Deployment Workflow",
    inventory="prod_inventory",
    extra_vars='{"version": "1.2.3"}'
)
client.workflow_job_template.create(new_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")

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Open an issue to discuss your proposed changes.
  2. Fork the repository.
  3. Clone the fork.
  4. Create a new branch (git checkout -b feature/my-feat-branch).
  5. Make your changes.
  6. Commit your changes (git commit -m "feat: Add mew feature").
  7. Push to the branch (git push origin feature/my-feat-branch).
  8. Open a pull request.

🧪 Testing

Run unit tests using pytest:

uv run pytest tests

🛠️ Roadmap

  • Add asynchronous calls support.
  • Add support for more AWX resources.

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.3.tar.gz (36.2 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.3-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyawx-0.1.3.tar.gz
Algorithm Hash digest
SHA256 182c8ea490532274b08483f186bfa5d9bf0954d8e6dedcce5b0bd3070b6526a2
MD5 f0d97bceec251e3883fce1242fc89cfa
BLAKE2b-256 1285ea8f29d86e39b35832d056c5ab666d249bfa27ade8d8bb12050c3aa3ceb3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyawx-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 72cc5747793e40409265b5544e5debd074b1208f66fea40c8c8e2b780e2f69e1
MD5 61b16dcbce3aeaa8f09d287a210501a2
BLAKE2b-256 bc0a8bb9f371415c69351c73b5b9af23dad9c4bcc4bee8db74a50d881e48aaa6

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