Skip to main content

Elliptic SDK for Python - A Requests wrapper for connecting to Elliptic APIs

Project description

Elliptic SDK for Python

Installation

The SDK is available on PyPI:

python -m pip install elliptic-python

This package requires Python 3.7 or greater

Usage

The SDK provides an instance of the popular Requests package, adding the necessary steps to authenticate each request using your Elliptic API key and secret.

from elliptic import AML

aml = AML(key="YOUR_ELLIPTIC_API_KEY", secret="YOUR_ELLIPTIC_API_SECRET")

# aml.client is an instance of a requests session
response = aml.client.get("/v2/analyses")

Webhook Signature Verification

Elliptic signs the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third-party. You can use the WebhookRequestVerifier class to verify the signature of a webhook request:

from http.server import HTTPServer, BaseHTTPRequestHandler
from elliptic import WebhookRequestVerifier

verifier = WebhookRequestVerifier(
    trusted_public_key="<Trusted public key, available from the Elliptic docs>",
    expected_endpoint_id="<Your endpoint id - this will be provided when your webhook integration is set up by Elliptic>",
)

class SimpleHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        try:
            content_length = int(self.headers.get("Content-Length", 0))

            post_data = self.rfile.read(content_length)
            params = {
                "webhook_id_header": self.headers.get("webhook-id"),
                "webhook_timestamp_header": self.headers.get(
                    "webhook-timestamp"
                ),
                "webhook_signature_header": self.headers.get(
                    "webhook-signature"
                ),
                "req_body": post_data,
            }
            message_id = verifier.verify(params)
            print("Verification successful, message ID:", message_id)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(b"Webhook received")
        except Exception as e:
            print("Verification failed:", e)
            self.send_response(401)
            self.end_headers()


def run(port=1337):
    server_address = ("", port)
    httpd = HTTPServer(server_address, SimpleHandler)
    print(f"Starting server on port {port}")
    httpd.serve_forever()


if __name__ == "__main__":
    run()

API Documentation

Documentation for Elliptic APIs can be found at the Elliptic Developer Center

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elliptic_python-0.9.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elliptic_python-0.9.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file elliptic_python-0.9.1.tar.gz.

File metadata

  • Download URL: elliptic_python-0.9.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/6.8.0-1031-aws

File hashes

Hashes for elliptic_python-0.9.1.tar.gz
Algorithm Hash digest
SHA256 975e0c9a25cd8f8b3f3a6cc2707f5d7761bc86f6b5f1dc740b0e5ebd57c6d5bd
MD5 69ff5890821cc9897e8613c67371488e
BLAKE2b-256 a2cffcacc1233b648c676249f65d83891f64ef24153f0c756aaec2f9bf75171a

See more details on using hashes here.

File details

Details for the file elliptic_python-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: elliptic_python-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/6.8.0-1031-aws

File hashes

Hashes for elliptic_python-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb16a128c77e1735a26878ad31bb88c0192b4e3016b33fc90d0eb9402f0931b
MD5 6c770f59d23f0a907d93a69ddf65abc3
BLAKE2b-256 69f9b1457e3f7d53d8b14de5752431c2d9820cd75161861658e78c21fac37fc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page