rsonghuster / fc-python-sdk-2.0

fc python sdk 2.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aliyun FunctionCompute Python SDK

https://travis-ci.org/aliyun/fc-python-sdk.svg?branch=master https://coveralls.io/repos/github/aliyun/fc-python-sdk/badge.svg?branch=master

Overview

The SDK of this version is dependent on the third-party HTTP library requests.

Running environment

Python 3.6+

Installation

Install the official release version through PIP (taking Linux as an example):

$ pip install xl-aliyun-fc2

You can also install the unzipped installer package directly:

$ sudo python setup.py install

Getting started

# -*- coding: utf-8 -*-
import fc2
import zipfile
import base64

# To know the endpoint and access key id/secret info, please refer to:
# https://help.aliyun.com/document_detail/52984.html
client = fc2.Client(
    endpoint='<Your Endpoint>',
    accessKeyID='<Your AccessKeyID>',
    accessKeySecret='<Your AccessKeySecret>')

# Create service.
client.create_service('demo')

zipFileBase64 = ''
with open('file.zip', 'rb') as f:
    content = f.read()
    zipFileBase64 = base64.b64encode(content).decode()

# Create function.
client.create_function('demo',
    {
        'functionName':'test_func',
        'runtime': 'python3',
        'handler': 'index.handler',
        'code': {
            'zipFile': zipFileBase64
        },
        'environmentVariables': {'testKey': 'testValue'}
    }
)

# Invoke function synchronously.
client.invoke_function('demo', 'test_func')

More resources

Contacting us

License

About

fc python sdk 2.0

License:MIT License


Languages

Language:Python 100.0%