Coder Social home page Coder Social logo

scaleway / serverless-api-framework-python Goto Github PK

View Code? Open in Web Editor NEW
8.0 7.0 2.0 599 KB

Framework for writing serverless APIs in Python, using Scaleway functions and containers.

Home Page: https://serverless-api-project.readthedocs.io

License: MIT License

Python 100.00%
python serverless faas scaleway

serverless-api-framework-python's Introduction

Serverless API Framework

PyPI version Documentation Status pre-commit.ci status

Serverless API Framework is a tool that lets you write and deploy serverless functions in Python. It bridges your code with the deployment configuration to make it a breeze to work with serverless functions.

Starts by defining a simple Python function:

from scw_serverless import Serverless

app = Serverless("hello-namespace")

@app.func(memory_limit=256)
def hello_world(event, context):
    return "Hello World!"

Deploy it with scw-serverless:

scw-serverless deploy app.py

Quickstart

Install

pip install scw-serverless

This will install the scw-serverless CLI:

scw-serverless --help

Writing and configuring functions

You can transform your Python functions into serverless functions by using decorators:

import os
import requests
from scw_serverless import Serverless

app = Serverless("hello-namespace")
API_URL = os.environ["API_URL"]

@app.func(memory_limit=256, env={"API_URL": API_URL})
def hello_world(event, context):
    return requests.get(API_URL)

The configuration is done by passing arguments to the decorator. To view which arguments are supported, head over to this documentation page.

Local testing

Before deploying, you can run your functions locally with the dev command:

scw-serverless dev app.py

This runs a local Flask server with your Serverless handlers. If no relative_url is defined for a function, it will be served on /name with name being the name of your Python function.

By default, this runs Flask in debug mode which includes hot-reloading. You can disable this behavior by passing the --no-debug flag.

Deploying

When you are ready, you can deploy your function with the scw-serverless CLI tool:

scw-serverless deploy app.py

The tool will use your Scaleway credentials from your environment and config file.

What’s Next?

To learn more about the framework, have a look at the documentation. If you want to see it in action, we provide some examples to get you started.

To run your Python functions locally, check out Scaleway Functions Python.

Contributing

We welcome all contributions.

This project uses pre-commit hooks to run code quality checks locally. We recommended installing them before contributing.

pre-commit install

serverless-api-framework-python's People

Contributors

astrojuanlu avatar cyclimse avatar dependabot[bot] avatar lucasscw avatar pre-commit-ci[bot] avatar redanrd avatar shillaker avatar thibaultjunin avatar thomas-tacquet avatar zoobdude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.