Skip to main content

Serverless Functions Python 💜

PyPI version pre-commit.ci status pre-commit.ci status

Scaleway Serverless Functions Python is a framework that simplifies Scaleway Serverless Functions local development. It enables you to debug your function locally and provide the event data format used in Scaleway Serverless Functions.

This library helps you to write functions but for deployment please refer to the documentation.

Get started with Scaleway Functions:

Testing frameworks for Scaleway Serverless Functions in other languages can be found here:

⚙️ Quickstart

You can use pip to install the framework:

pip install scaleway-functions-python
# handler.py

# Standard entrypoint to a Scaleway serverless function
def handler(event, context):
    if event["httpMethod"] != "GET":
         return {"statusCode": 405, "body": "Invalid method!"}
    return "Hello World!"

if __name__ == "__main__":
    # The import is conditional so that you do not need
    # to package the library when deploying on Scaleway Functions.
    from scaleway_functions_python import local
    local.serve_handler(handler, port=8080)

You can then run your function locally:

$ python handler.py
$ curl http://localhost:8080
> Hello World!
$ curl -X POST http://localhost:8080
> Invalid method!

🚀 Features

This repository aims to provide a better experience on local testing, utils, and documentation

🏡 Local testing

What this package does:

  • Format Input: Serverless Functions have a specific input format encapsulating the body received by functions to add some useful data. The local testing package lets you interact with the formatted data.
  • Advanced debugging: To improve developer experience you can run your handler locally and debug it by running your code step-by-step or reading output directly before deploying it.

What this package does not:

  • Simulate performance: Scaleway FaaS lets you choose different options for CPU/RAM that can have an impact on your development. This package does not provide specific limits for your function on local testing but you can profile your application or you can use our metrics available in Scaleway Console to monitor your application.
  • Deploy functions: When your function is uploaded we package it in an environment that can be different than yours. Our build pipelines support several dependencies but sometimes require specific system dependencies (especially those related to lib c) that we don't support If you have compatibility issues, please see the help section.

🧱 Type hints

The framework provides some types hints to make it easier to develop your handler. See this example for more information on how to use them.

❓ FAQ

Why do I need an additional package to call my function?

Your Function Handler can be served by a simple HTTP server but Serverless Ecosystem involves a lot of different layers that will change changes the headers, input and output of your function. This package aims to simulate everything your request will go through to help you debug your application properly. This library is not mandatory to use Scaleway Serverless Functions.

How my function will be deployed

To deploy your function please refer to our official documentation.

Do I need to deploy my function differently?

No, this framework does not affect deployment or performance.

How can I use my packaged dependencies?

When deploying Python functions, your dependencies must be bundled in a package folder at the root of your project. For local testing, you can set PYTHONPATH=$(pwd)/package to make your dependencies available. This can be useful to avoid packaging your dependencies in multiple locations.

Please note that this does not work for native dependencies as the Scaleway Python runtime is different from your local machine.

Why are my logs not showing up when using the print function?

By default, stdout is buffered in Python, so calling print without flush=True can lead to missing logs when running locally. If you experience this issue, you can export the environment variable PYTHONUNBUFFERED with export PYTHONUNBUFFERED=1. This will flush stdout on every print call.

🎓 Contributing

We welcome all contributions to our open-source projects, please see our contributing guidelines.

Do not hesitate to raise issues and pull requests we will have a look at them.

📭 Reach Us

We love feedback. Feel free to:

Release files for scaleway-functions-python 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scaleway-functions-python 0.2.3
File Size Uploaded
scaleway_functions_python-0.2.3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scaleway-functions-python 0.2.3
File Interpreter ABI Platform
scaleway_functions_python-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / scaleway_functions_python-0.2.3.tar.gz

Download URL scaleway_functions_python-0.2.3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
55d4d3b3f0ff68996924c99038e85658df3d065c5233877a298888d706428dd4
BLAKE2b-256 checksum
How to use checksums
a79f1897c585cdc70f08512ae382aa6973920b4f34388cd166b7f2951fcb772d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

Release files / scaleway_functions_python-0.2.3-py3-none-any.whl

Download URL scaleway_functions_python-0.2.3-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56a1028b5f22e1da1cd75f2334e3ab548189efa4782d42e406c27b63c44ae279
BLAKE2b-256 checksum
How to use checksums
28647ee7532c51c42ed9063c8f165fe13ed51cdbd6b4f76809c4865836f9e9e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.13.2 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page