Skip to content

Python Client

WERK24 is designed to make handling Technical Drawings as convenient as possible. Steps to get you up and running with our Python Client.

Install the Client

Prerequisites for Installing the Client

  1. Python Installation and Configuration: Python needs to be installed and configured on your system. Configuration involves adding Python to your system's PATH environment variable. The specific instructions for doing this will vary depending on your operating system. If you are fimilar with the python installation you can use the text instructions below to install the python on your system. For more step by step instructions you can follow the links provided below.

Step-by-step instructions for windows

  1. Pip Installation: Pip, the Python package manager, is usually installed by default when you install Python. Therefore, it's likely already available if you have Python.

1. Installing Python:

Please follow these self-explanatory tutorials below to install the Python on Windows and popular Linux distributions like Ubuntu.

1.1 On Windows

Installing Python on Windows (Markdown Language) Here are the steps to install Python on Windows using Markdown:

  1. Download the Installer:

Visit the official Python downloads page: Get python here!! Choose the latest stable release or a specific version if needed. Select the installer for your system architecture (32-bit or 64-bit). 2. Run the Installer:

Double-click the downloaded installer file. Important: Check the box for "Add Python 3.x to PATH" (where "x" is the version number). This ensures you can run Python commands from the command line or terminal. Click "Install Now". 3. Verify Installation:

Press ⊞ Win + R to open the Run dialog. Type cmd and press Enter to open the command prompt. Type python --version and press Enter. If the installation is successful, you should see the installed Python version displayed.

1.2 On Ubuntu

if you are familiar with the installation of python on ubuntu you can use the following text instructions to install the python on your system. For more step by step instructions you can follow the links provided below. Step-by-step instructions for Ubuntu

Here's how to install Python on Ubuntu:

1. Update Package Lists:

sudo apt update

2. Install Python:

There are two main methods:

Method A: Using the Official Ubuntu Repositories (Recommended)

This method installs the latest stable Python version available in your Ubuntu repositories.

sudo apt install python3

Method B: Using a Personal Package Archive (PPA) (Optional)

This method allows you to install a specific Python version, potentially newer than the one available in the official repositories.

Important Note: Using PPAs is not always recommended as they may introduce compatibility issues or security risks. Use them with caution and only if necessary.

Here's an example using the deadsnakes PPA for installing Python 3.11:

# Add the deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa

# Update package lists again
sudo apt update

# Install Python 3.11
sudo apt install python3.11

3. Verify Installation:

python3 --version

WERK24 provides an easy-to-use and easy-to-extend Python-based client. Install our Python Client using pip

based on which operating system you are using. on windows, you need to press Win + R and type cmd and press enter to open the command prompt. This should open a terminal window. on Windows terminal you can use the following command to install the client. pip install werk24 On Linux, you need to open the terminal by CTRL + ALT + T and use the following command pip install werk24 to install the client.

bash pip install werk24

Configure the Client

The Client uses AWS Cognito to handle Authentication. This has several advantages:

  • Security updates are handled by a dedicated team
  • Standard libraries are available for a large range of languages
  • You will be able to maintain individual accounts for your own customers.

During the registration process, we provide you with a .werk24 file, which contains all the information you will need. It will look similar to this: You may see some additional information in the file, but her it mostly contains the following information

W24TECHREAD_AUTH_REGION="eu-central-1"
W24TECHREAD_AUTH_TOKEN="CEdF9Dx00eFAbEeaFCb2b66cbxx6cb1D89a37f4d5bD793d9fbFAxxBc9b29"

Important

When you choose to use your .werk24 file directly, add .werk24 to your .gitignore file to ensure that the credentials remain stored locally. For production environments we strongly recommend setting the credentials as ENVIRONMENT VARIABLES.

For more details see Authentication

Test the Client

You can check whether the client is installed and configured correctly by submitting a simple Techread request through the CLI. The request submits the technical drawing to the API and returns a thumbnail of the individual sectionals. To be able to see the image, ensure that you have the Pillow package installed.

bash pip install Pillow

After that, you can submit the request by running

bash w24cli techread --ask-page-thumbnail ./your-file.pdf

You should now see one or more images of the individual cuts on your Technical Drawing. Have a look at the additional details at the CLI Documentation.

Send your first programmatic request

After you have installed python and the werk24 client, you can use the following code to send your first programmatic request to the WERK24 API. Create a new file and name it drawing_bytes.py and add the following code to it. Note: you can name the file anything you want. Hint: you can use the IDE of your choice to create the file and add the code to it. The common IDEs are PyCharm, Visual Studio Code, and Jupyter Notebook. Find more information about the IDEs more info Pycharm, VsStudio, and Jupyter Notebook. see how to install and use the IDEs Pycharm, VsStudio, and JupyterNotebook.

```python import asyncio from werk24 import Hook, W24TechreadClient, W24AskVariantMeasures from drawing_bytes import get_drawing_bytes # define your own

async def print_measures_of_drawing(drawing_bytes):

hooks = [Hook(ask=W24AskVariantMeasures(), function=print)]

async with W24TechreadClient.make_from_env() as session:
    await session.read_drawing_with_hooks(drawing_bytes, hooks)

drawing_bytes = get_drawing_bytes( './your-file.pdf')

asyncio.get_event_loop().run_until_complete (print_measures_of_drawing(drawing_bytes)) ```

Run the file:

Please run this file by right-clicking on the file and selecting the option to run the file. You can also use the terminal to run the file by navigating to the file location and using the following command python drawing_bytes.py to run the file.

What the code does?:

The code above is a simple example of how to use the werk24 client to send a request to the WERK24 API. The code sends a request to the API to read the drawing and print the measures of the drawing. The code uses the asyncio library to run the code asynchronously. The code uses the werk24 library to send the request to the API. The code uses the W24TechreadClient class to send the request to the API. The code uses the W24AskVariantMeasures class to ask the API to return the measures of the drawing. The code uses the Hook class to define the function to be called when the request is successful. The code uses the print_measures_of_drawing function to send the request to the API. The code uses the get_drawing_bytes function to get the drawing bytes of the drawing. The code uses the async and await keywords to run the code asynchronously. The code uses the async with statement to create an asynchronous context manager. The code uses the session object to send the request to the API. The code uses the read_drawing_with_hooks method to send the request to the API. The code uses the drawing_bytes variable to pass the drawing bytes to the API. The code uses the hooks variable to pass the hooks to the API. The code uses the function attribute of the Hook class to define the function to be called when the request is successful. The code uses the W24TechreadClient.make_from_env method to create a new session object. The code uses the print function to print the measures of the drawing. The code uses the asyncio.get_event_loop().run_until_complete method to run the code asynchronously.