Skip to main content

Code Preparation

Dependencies

Clearly specify your Python dependencies to ensure consistent execution environments:
# requirements.txt
pandas>=1.5.0
numpy>=1.24.0
scikit-learn>=1.2.0
If no requirements.txt is provided we will attempt to automatically detect any imports that could be needed during execution. However, this can be unreliable and directly stating requirements is encouraged.

File Paths

Use paths relative to your current working directory to ensure your code works both locally and on the cloud:
from pathlib import Path

# Good: Relative paths
data_path = Path("data/input.csv")
output_path = Path("outputs/results.json")

# Avoid: Absolute paths
# data_path = "/home/user/project/data/input.csv"

Error Handling

Include proper error handling for robust execution:
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

try:
    # Your processing code
    result = process_data()
    logger.info("Processing completed successfully")
except Exception as e:
    logger.error(f"Processing failed: {e}")
    raise

Execution Optimization

Progress Monitoring

Provide feedback during long-running operations:
from tqdm import tqdm

for item in tqdm(data, desc="Processing"):
    process_item(item)

Checkpointing

Save intermediate results for long-running processes:
import pickle

# Save checkpoint
with open('checkpoint.pkl', 'wb') as f:
    pickle.dump(state, f)

# Resume from checkpoint
with open('checkpoint.pkl', 'rb') as f:
    state = pickle.load(f)

Using the API

Authentication

Always store credentials securely:
import os

# Use environment variables
api_token = os.environ.get('LYCEUM_API_TOKEN')

# Never hardcode credentials in your code

Error Handling

Handle API responses properly:
import requests

response = requests.post(
    'https://api.lyceum.technology/api/v2/external/execution/streaming/start',
    headers={'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'},
    json={'code': code, 'nbcode': 0, 'execution_type': 'cpu'}
)

if response.status_code == 200:
    result = response.json()
else:
    print(f"Error: {response.status_code} - {response.text}")

Troubleshooting

Common Issues

Execution Fails to Start
  • Check your authentication token is valid
  • Verify you have sufficient credits
  • Ensure your code syntax is correct
Files Not Found
  • Verify files are uploaded to cloud storage
  • Check file paths are correct
  • Use the storage API to list available files
Out of Memory Errors
  • Process data in smaller chunks
  • Choose a machine type with more memory
  • Optimize your code to use less memory

Getting Help

  • Check execution logs for detailed error messages
  • Contact support at [email protected]
  • Review the API documentation for endpoint details
These best practices will help you use Lyceum Cloud effectively. For specific API endpoints and parameters, refer to the API Reference section.