Python setup
Requirements
To use the UpRock API with Python, you need Python 3.8 or higher and pip (Python’s package installer).
Create a Virtual Environment
Creating a virtual environment isolates your project dependencies from other Python projects.
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate# Create virtual environment
python3 -m venv venv
# Activate virtual environment
venv\Scripts\activateInstall Required Dependencies
pip install requests python-dotenvDependencies installed:
requests- HTTP library for making API callspython-dotenv- Loads environment variables from.envfiles
Configure Environment Variables
Ensure you have set up your environment variables as described in the get your API keys guide. Your .env file should contain:
UPROCK_API_KEY=your-api-key-here
# UPROCK_BASE_URL is optional - defaults to https://edge.uprock.comNever commit your .env file to version control. Add it to .gitignore.
Verify Your Setup
Create a test_setup.py file and run the code below to verify your setup:
from dotenv import load_dotenv
import os
import requests
# Load environment variables from .env file
load_dotenv()
# Get configuration
api_key = os.getenv('UPROCK_API_KEY')
base_url = os.getenv('UPROCK_BASE_URL', 'https://edge.uprock.com')
# Validate API key is set
if not api_key:
print("Error: UPROCK_API_KEY not set")
exit(1)
# Test API connection
response = requests.get(
f"{base_url}/crawl/v1/health",
headers={"Authorization": f"Bearer {api_key}"}
)
# Display result
if response.status_code == 200:
print("✓ Setup verified - Ready to use UpRock Crawl API")
else:
print(f"✗ Setup failed with status code: {response.status_code}")Run the verification script:
python test_setup.pyExpected Output
✓ Setup verified - Ready to use UpRock Crawl APICommon failure codes:
401- Invalid or missing API key403- Inactive plan or insufficient permissions404- Incorrect base URL
Troubleshooting
Below are solutions to common setup issues. If these don't resolve your problem, reach out to support@uprock.com.
Import Errors
If you encounter import errors, ensure your virtual environment is activated:
source venv/bin/activatevenv\Scripts\activateAPI Key Not Found
Verify your .env file is in the same directory as your script and the variable name is exactly UPROCK_API_KEY.
Connection Errors
If behind a corporate proxy, configure the HTTPS_PROXY environment variable as described in the get your API keys guide.