Skip to main content

A Python SDK for FastOTP API

Project description

FastOTP SDK Documentation

Overview

The FastOTP SDK is a Python library for interacting with the FastOTP API. It supports various frameworks including Django, FastAPI, and Flask. This SDK allows you to generate, validate, and retrieve OTPs (One-Time Passwords) easily.

Installation

To install the FastOTP SDK, use pip:

pip install fastotp_sdk

Configuration

You need an API key to authenticate your requests. You can find your API key in the FastOTP Dashboard.

Usage

Importing the SDK

To use the SDK, import the FastOTPClient class from the fastotp module and instantiate it with your API key.

from fastotp import FastOTPClient

api_key = "your_api_key"
client = FastOTPClient(api_key)

Generating an OTP

To generate an OTP, use the generate_otp method. Provide a dictionary with the necessary payload.

payload = {
    "type": "numeric",
    "identifier": "user@example.com",
    "delivery": {"email": "user@example.com"},
    "validity": 123,
    "token_length": 6,
}
response = client.generate_otp(payload)
print(response)

Validating an OTP

To validate an OTP, use the validate_otp method. Provide a dictionary with the token and identifier.

payload = {
    "token": "123456",
    "identifier": "user@example.com"
}
response = client.validate_otp(payload)
print(response)

Retrieving an OTP

To retrieve an OTP by its ID, use the get_otp method.

otp_id = "some-otp-id"
response = client.get_otp(otp_id)
print(response)

Framework-Specific Examples

Django Example

Create a view to generate an OTP in your Django project.

from django.http import JsonResponse
from fastotp import FastOTPClient

api_key = "your_api_key"
client = FastOTPClient(api_key)

def generate_otp(request):
    payload = {
        "type": "numeric",
        "identifier": "user@example.com",
        "delivery": {"email": "user@example.com"},
        "validity": 123,
        "token_length": 6,
    }
    response = client.generate_otp(payload)
    return JsonResponse(response)

FastAPI Example

Create an endpoint to generate an OTP in your FastAPI project.

from fastapi import FastAPI
from fastotp import FastOTPClient

app = FastAPI()
api_key = "your_api_key"
client = FastOTPClient(api_key)

@app.post("/generate-otp/")
async def generate_otp(payload: dict):
    return client.generate_otp(payload)

Flask Example

Create a route to generate an OTP in your Flask project.

from flask import Flask, request, jsonify
from fastotp import FastOTPClient

app = Flask(__name__)
api_key = "your_api_key"
client = FastOTPClient(api_key)

@app.route("/generate-otp", methods=["POST"])
def generate_otp():
    payload = request.json
    return jsonify(client.generate_otp(payload))

if __name__ == "__main__":
    app.run()

Error Handling

The SDK raises a FastOTPError exception for any errors returned by the FastOTP API.

try:
    response = client.generate_otp(payload)
except FastOTPError as e:
    print(f"Error: {e}")

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License.

Contact

For any issues or questions, please contact your_email@example.com.

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

fastotp_sdk-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

fastotp_sdk-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fastotp_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: fastotp_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for fastotp_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ad75c1323201037f8767c9e7ec08eb49bd0dc94ba40335a833012b3a5c497e9f
MD5 7949cca51ca6859ba31f147f66224414
BLAKE2b-256 ef528c6fbd297be01aa0a36d2c4f1845027925b15abfcd837f9e2d2afd699623

See more details on using hashes here.

File details

Details for the file fastotp_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastotp_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for fastotp_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc288a7fa962d8ededcfcd7c43a2ff0deaabc444f97f3d740f739b613a5a04a2
MD5 00446ba159c03120661fe81af32bc00c
BLAKE2b-256 149dfc56b9b5d0680ce4bcd24aa88760c7d2db4348b4f1619f363f6386412411

See more details on using hashes here.

Supported by

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