Python Request
The Werk24 Python client enables seamless extraction of structured data from technical drawings. This section demonstrates different implementation approaches: synchronous processing, asynchronous processing, and callback-based integration.
Working in another language?
You can also submit drawings from any tech stack using our WebSocket interface or webhook callbacks. The WebSocket endpoint is language agnostic and works great with Java, JavaScript/Node.js, TypeScript, C#, Go, PHP, Ruby, Rust, or C++. See Webhooks for registering a callback URL.
Choose the Right Approach
Use the table below to determine which implementation best suits your use case. All implementations are always possible, but some might suit your use-case more than others.
| Use Case | Synchronous | Asynchronous | Callback |
|---|---|---|---|
| Quick, one-time extraction | ~ | ~ | |
| Processing multiple drawings concurrently from local machine | ~ | ~ | |
| Integration with web applciations or APIs | ~ | ~ |
Synchronous Implementation
If you need a quick way to extract metadata from a technical drawing, the synchronous approach is the easiest method:
Explanation
get_test_drawing()provides a sample drawing to test the function.read_drawing_sync()sends the drawing to Werk24 and retrieves structured metadata.- The response is printed as a list of TechreadMessages, ready for further processing.
Limitation
This method blocks execution until the request is complete. It is not suitable for processing multiple drawings concurrently or integrating with asynchronous systems.
Asynchronous Implementation
For more complex applications, you can use an asynchronous approach to handle requests efficiently, allowing the system to process multiple drawings simultaneously.
Explanation
- Asynchronous processing: asyncio.run() allows non-blocking execution, making it suitable for batch processing or integration into web applications.
- Callback function (recv): Handles responses from the Werk24 server and processes the returned data.
- Hooks: Define the extraction request (AskMetaData()) and the function to execute when the response is received.
- Werk24Client(): Manages the connection and request submission.
This approach is ideal for large-scale applications where multiple drawings need to be processed efficiently.
Callback
For seamless integration with web applications or APIs, you can use Werk24's callback-based approach. This allows the server to notify your application when results are ready.
Producer (Sending Requests)
Explanation
- Callback URL: Defines where Werk24 should send results when processing is complete.
- Authorization Headers: Secure the API with a token.
- Non-blocking processing: The client submits the request and moves on, instead of waiting.
Consumer
Explanation
- FastAPI Endpoint (/werk24-callback): Handles incoming responses from Werk24.
- TechreadMessage: The structured response containing extracted data.
- Logs and error handling: Prints success or failure details for each request.
Checking system status
Before sending drawings, you can verify that the Werk24 API is available:
The returned SystemStatus model provides a high-level indicator such as "ok" along with optional details.
For guidance on integrating these checks into uptime dashboards or alerts, see System Status Monitoring.