Python · Industrial Automation

Python REST API for Industrial Automation

Use Python REST APIs for industrial automation with requests. Send plant data with GET/POST, JSON payloads, timeouts, authentication headers and robust error handling.

Practical Python Automation Context Copy-Paste Examples Code Architecture

Learning Overview

Python Learning SeriesPython for Industrial AutomationPractical

Learning Goal

  • Use Python REST APIs for industrial automation with requests. Send plant data with GET/POST, JSON payloads, timeouts, authentication headers and robust error handling.
  • Run the examples in VS Code using the project environment prepared in earlier topics.
  • Understand where this topic fits in the complete SQL, reporting and Industry 4.0 workflow.
Quick answer

Use Python REST APIs for industrial automation with requests. Send plant data with GET/POST, JSON payloads, timeouts, authentication headers and robust error handling.

Architecture: Python REST API Integration

Code-Based Architecture

Python REST API Integration

1

Plant / SQL Data

Build application payload

dict
2

Python requests

Create HTTP request

requests.post
3

REST Endpoint

HTTPS URL

/api/events
4

Server

Validate/process request

API service
5

Response

Status + JSON

response.json()
6

Logging

Record success/failure

logger.info/error
Plant / SQL DataPython requestsREST EndpointServerResponseLogging

1. Install requests

python -m pip install requests

2. GET data from an API

import requests response = requests.get( "https://api.example.com/status", timeout=10,
)
response.raise_for_status()
print(response.json())

3. POST plant data as JSON

payload = { "sqf_no": 2, "charge_no": "CHG-001", "temp_act": 850.2,
} response = requests.post( "https://api.example.com/events", json=payload, timeout=10,
)
response.raise_for_status()

4. Add an authorization header

headers = { "Authorization": "Bearer YOUR_TOKEN", "Accept": "application/json",
}
response = requests.get(url, headers=headers, timeout=10)
Do not hard-code production tokens in source code. Use your approved secret-management method.

5. Handle timeout and HTTP errors

import requests try: response = requests.get(url, timeout=10) response.raise_for_status()
except requests.Timeout: print("API timeout")
except requests.RequestException as error: print("API request failed:", error)

6. REST integration checklist

  • Use HTTPS for external/sensitive traffic
  • Always set timeouts
  • Validate JSON fields and engineering units
  • Handle HTTP status codes and retries deliberately
  • Store credentials/tokens securely

Frequently Asked Questions

What is a REST API in industrial automation?

It is an HTTP-based interface that lets authorized systems exchange structured data, commonly JSON, between plant, enterprise and cloud applications.

Why should Python requests have a timeout?

Without a timeout, a network call can wait indefinitely and block an automation/reporting workflow.

Can REST APIs replace OPC UA?

They serve different integration patterns. OPC UA is designed for industrial interoperability and information models; REST is common for web/enterprise application integration.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience
Complete Python for Industrial Automation Learning Path

Use Previous / Next for sequential training, or open any topic directly.

Complete

Continue with the next topic in the Python for Industrial Automation learning path.

Open Learning Path
Python for Industrial Automation

Python REST API Integration

Use Python REST APIs for industrial automation with requests. Send plant data with GET/POST, JSON payloads, timeouts, authentication headers and robust error handling.

Content reviewed: 14 September 2026

☎ Call WhatsApp ✉ Email Enquire Now