Deploy a python function

This guide walks you through deploying, testing, monitoring, and managing a Python function on PandaEdge.

Prerequisites

  • A PandaEdge account

  • Basic knowledge of Python

  • Your function code ready for deployment

  • Appropriate access role (Owner or Admin for deployment)

Supported Python Versions

  • Python 3

  • Python 3.9 (Default)

Deployment Steps

1. Create a New Function

  1. Navigate to the Edge Functions dashboard

  2. Click "Create New" button

  3. Select "Python" as your runtime

  4. Choose your preferred Python version

2. Function Naming

Ensure your function name is:

  • 4-12 characters long

  • Contains only lowercase letters, numbers, and hyphens

  • Unique within your organization

3. Write Your Function

Basic function template:

4. Configure Function

5. Manage Dependencies

Create requirements.txt:

Version Management

1. Version History

  • View all deployed versions

  • See deployment timestamps

  • Track authors and changes

  • Compare version performance

2. Rollback Capability

  • Roll back to any previous version

  • Instant version switching

  • No downtime during rollback

  • Automatic version tracking

Testing Features

1. Basic Testing

Use the built-in test interface to:

  • Send test requests

  • View responses

  • Check execution time

  • Monitor memory usage

2. Test Cases

Create reusable test cases:

3. Debugging

  1. Set breakpoints in your code

  2. Inspect variables during execution

  3. View call stack

  4. Step through code execution

4. Mock Data Generation

Generate test data for:

  • Strings

  • Numbers

  • Booleans

  • Arrays

  • Objects

Function Examples

1. Data Processing Function

2. Version-Aware Function

Best Practices

1. Version Control

  • Tag versions meaningfully

  • Document changes

  • Test before rollback

  • Monitor version performance

  • Keep deployment history

2. Error Handling

3. Resource Management

  • Use appropriate memory allocation

  • Set reasonable timeouts

  • Clean up resources

  • Use context managers for file/network operations

4. Security

  • Validate input data

  • Sanitize output

  • Use environment variables for secrets

  • Implement proper authentication

Troubleshooting

1. Common Issues

  1. Memory Issues

    • Monitor memory usage

    • Use generators for large datasets

    • Clean up resources

    • Increase memory allocation if needed

  2. Version Issues

    • Check version history

    • Verify deployment logs

    • Test previous versions

    • Monitor version metrics

  3. Dependency Issues

    • Verify package versions

    • Check compatibility

    • Update requirements.txt

    • Review package size

2. Performance Optimization

  1. Code Optimization

    • Use appropriate data structures

    • Implement caching when possible

    • Optimize database queries

    • Minimize external calls

  2. Resource Management

    • Monitor memory usage

    • Clean up resources

    • Use connection pooling

    • Implement proper error handling

Last updated