Published on

LoginLlama's Python SDK is Now Available

Loginllama is excited to announce the release of the Python SDK. This makes it even easier to integrate Loginllama to your Python application - including into Django and Flask apps. This makes it simplier for developers to easily enhance their systems security.

Key Features of the LoginLlama Python SDK:

  • AI Powered Login Behaviour Insights: Analyze login patterns and detect anomalies with machine learning.
  • Real-Time Fraud Detection: Identify and respond to suspicious activities instantly.
  • Enhanced Customer Trust: Boost user confidence with robust security features.
  • Easy to Use SDK and API: Seamlessly integrate security into existing systems.
  • Compliance with Security Standards: Ensure your platform meets regulatory requirements for data protection.

Example Usage

Here’s a basic example of how to use the LoginLlama Python SDK:

Installation

To install the SDK, use pip:

pip install loginllama

Initialization

Initialize the LoginLlama class with your API token:

from loginllama.loginllama import LoginLlama

loginllama = LoginLlama("YOUR_API_TOKEN")

Checking Login Status

Check the login status using direct parameters:

login_check_result = loginllama.check_login(
    ip_address="192.168.1.1",
    user_agent="Mozilla/5.0",
    identity_key="user123"
)

print("Status:", login_check_result.status)
print("Message:", login_check_result.message)
print("Codes:", [code.value for code in login_check_result.codes])

Using with Flask

Here's how to integrate with a Flask application:

from flask import Flask, request
from loginllama.loginllama import LoginLlama

app = Flask(__name__)
loginllama = LoginLlama(api_token='your_api_token')

@app.route('/login_check', methods=['POST'])
def login_check():
    identity_key = request.form.get('identity_key')
    if not identity_key:
        return "identity_key is required", 400

    try:
        login_check_result = loginllama.check_login(request=request, identity_key=identity_key)
        return {
            "status": login_check_result.status,
            "message": login_check_result.message,
            "codes": [code.value for code in login_check_result.codes]
        }
    except ValueError as e:
        return str(e), 400
    except Exception as e:
        return str(e), 500

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

Using with Django

And for Django applications:

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from loginllama.loginllama import LoginLlama

@csrf_exempt
def login_check(request):
    if request.method == 'POST':
        identity_key = request.POST.get('identity_key')
        if not identity_key:
            return JsonResponse({"error": "identity_key is required"}, status=400)

        try:
            loginllama = LoginLlama(api_token='your_api_token')
            login_check_result = loginllama.check_login(request=request, identity_key=identity_key)
            return JsonResponse({
                "status": login_check_result.status,
                "message": login_check_result.message,
                "codes": [code.value for code in login_check_result.codes]
            })
        except ValueError as e:
            return JsonResponse({"error": str(e)}, status=400)
        except Exception as e:
            return JsonResponse({"error": str(e)}, status=500)

    return JsonResponse({"error": "Invalid request method"}, status=405)

With the release of this Python SDK, LoginLlama continues to lead in providing cutting-edge security solutions that are easy to integrate and essential for protecting user data.