Code Monkey home page Code Monkey logo

signway-python-sdk's Introduction

Signway Python SDK

The Signway Python SDK enables you to generate signed URLs for the Signway service. Signway facilitates a secure, direct request from a client-side application to a third-party API without exposing sensitive credentials.

Install

To install the Signway Python SDK, run the following command:

pip install signway-sdk

Usage

import os
from signway_sdk import sign_url

print(sign_url(
    # The Application ID.
    # It can be either a Signway managed Application ID (ex: ID0123ABCD...),
    # or the ID provided when launching your own Signway instance (`$ signway <ID> <SECRET>`)
    #                                                                          ^
    id=os.environ["SW_ID"],
    # The Application Secret paired with the provided Application ID.
    # It can be either a Signway managed Application Secret (ex: Gi8p1uZ39cg...),
    # or the Secret provided when launching your own Signway instance (`$ signway <ID> <SECRET>`)
    #                                                                                   ^
    secret=os.environ["SW_SECRET"],
    # The Signway host that will proxy the signed request.
    # If you are using Signway managed, it should be "https://api.signway.io",
    # otherwise, it should be the url where your own Signway instance is listening.
    host="https://api.signway.io",
    # To which URL the request will be proxy-ed by the Signway host. This url
    # will be embedded into your signed url as a query parameter, that way
    # Signway will know where to proxy the request.
    proxy_url="https://api.openai.com/v1/completions",
    # The validity period of signed URL in seconds. Signway will reject the request
    # if this number of seconds have happened since the signed URL was created.
    expiry=10,
    # The method that will be used for performing the request through Signway.
    # If a signed URL with a POST method is created, but when performing the
    # HTTP query to Signway a GET method is used, the request will be rejected.
    method="POST",
    # [Optional] headers to include in the signature. Any headers set here must
    # also be included in the final HTTP request with the exact value provided here.
    # Additional headers not present here can anyways be sent freely and Signway will
    # not take them into account for validating the request's signature.
    headers={"Content-Type": "application/json"},
    # [Optional] which body to include in the signature. If provided, the final
    # HTTP request must include exactly this body, otherwise the Signway will reject
    # the request. If not provided, the body will not be taken into account for
    # calculating the signature, and consumers can freely send any body they want.
    body='''{
  "model": "text-davinci-003",
  "stream": true,
  "prompt": "Say this is a test"
}'''
))

signway-python-sdk's People

Contributors

gabotechs avatar

Watchers

 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.