Lets start by walking through how to setup an environment and install the Kodexa Python SDK. This SDK can be used to interact with almost all aspects of Kodexa’s Documents and Platfrom.
Installing Python 3.11
- Visit the official Python website: https://www.python.org/downloads/
- Download the Python 3.11 installer for your operating system
- Run the installer and follow the installation wizard
- Make sure to check the box that says "Add Python 3.11 to PATH" during installation
Setting up a Virtual Environment
- Open a terminal or command prompt
- Navigate to your project directory
- Create a new virtual environment:
- Activate the virtual environment:
- On Windows:
- On macOS and Linux:
python -m venv kodexa_env
kodexa_env\\Scripts\\activate
source kodexa_env/bin/activate
Installing Kodexa
With your virtual environment activated, install Kodexa using pip:
pip install kodexa
Connecting to Kodexa Using a Python SDK
- Go to the Kodexa Platform: kodexa.platform.ai
- Click on your profile picture in the top right corner and select Profile
- Navigate to the tab listed API Tokens and then click on New Access Token
- Enter the name of your token and click Generate New Access Token to create and view the token
- Copy the token to your clipboard as you will not be able to view it again after creation
Writing a Script to Connect to KodexaClient
Create a new Python file called kodexa_script.py
and add the following code:
import os
from kodexa.client.client import KodexaClient
# Set up environment variables
os.environ['KODEXA_URL'] = '<https://your-kodexa-url.com>'
os.environ['KODEXA_ACCESS_TOKEN'] = 'your-access-token'
# Create a KodexaClient instance
client = KodexaClient(
url=os.environ.get('KODEXA_URL'),
access_token=os.environ.get('KODEXA_ACCESS_TOKEN')
)
# Use the client to interact with the Kodexa platform
# For example, get information about the current user
me = client.me
print(f"Logged in as: {me.email}")
# Add more Kodexa operations here
This script demonstrates how to use environment variables to securely store your Kodexa URL and access token. It then creates a KodexaClient instance using these environment variables and performs a simple operation to get information about the current user.
To run the script, make sure your virtual environment is activated and then execute:
python kodexa_script.py
Remember to replace '<https://your-kodexa-url.com>'
and 'your-access-token'
with your actual Kodexa URL and access token.
By using environment variables, you can keep sensitive information out of your code and make it easier to manage different configurations for development, testing, and production environments.
← Previous