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.
Open a terminal or command prompt
Navigate to your project directory
Create a new virtual environment:
python -m venv kodexa_env
Activate the virtual environment:
On Windows:
kodexa_env\\\\Scripts\\\\activate
On macOS and Linux:
source kodexa_env/bin/activate
With your virtual environment activated, install Kodexa using pip:
pip install kodexa
Create a new Python file called kodexa_script.py
and add the following code:
import os
from kodexa 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
Next →
On this page