GithubHelp home page GithubHelp logo

ipeluwa / fastotp_sdk Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 10 KB

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.

Home Page: https://fastotp.co

License: MIT License

Python 100.00%

fastotp_sdk's Introduction

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": "[email protected]",
    "delivery": {"email": "[email protected]"},
    "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": "[email protected]"
}
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": "[email protected]",
        "delivery": {"email": "[email protected]"},
        "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 [email protected].

fastotp_sdk's People

Contributors

ipeluwa avatar

Stargazers

Inu John avatar Michael Okoh avatar

Watchers

 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.