Python Quickstart

Getting started with the Python Sift client library

Credentials

Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions on how to retrieve the API key and URL and can be found in the authentication section of the documentation.

To connect to Sift's gRPC API using Python we will use sift-stack-py.

  1. Inside of new main.py install sift-stack-py by running the following command:

    pip install sift-stack-py==0.3.0rc3

    Release Candidate

    Note that at the time of writing this, the service we will use for this example is not yet available on the current stable version. To get the most recent stable version:

    pip install sift-stack-py
  2. With the dependencies installed create a Python script with the following contents:

    import os
     
    from sift.ping.v1.ping_pb2 import PingRequest
    from sift.ping.v1.ping_pb2_grpc import PingServiceStub
    from sift_py.grpc.transport import SiftChannelConfig, use_sift_channel
     
    if __name__ == "__main__":
        apikey = os.getenv("SIFT_API_KEY")
        assert apikey
     
        uri = os.getenv("BASE_URI")
        assert uri
     
        channel_config: SiftChannelConfig = {
            "apikey": apikey,
            "uri": uri,
        }
     
        with use_sift_channel(channel_config) as channel:
            response = PingServiceStub(channel).Ping(PingRequest())
            print(response)
  3. Execute the program from your commandline with the SIFT_URI and SIFT_API_KEY environment variables from the authentication page:

    BASE_URI=$SIFT_GRPC_URL:$PORT_NUM SIFT_API_KEY=$API_KEY python main.py

    If everything was setup correctly you should see the following printed to your standard output:

    response: "Hello from Sift!"

On this page

No Headings