Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Virtual Queue Python SDK Examples

Here you can find examples on how to use this SDK
File renamed without changes.
31 changes: 31 additions & 0 deletions examples/flask/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Flask Example for VQueue's Python SDK

This is an example of how to use `vqueue-sdk` within a Flask app.

## Setup

1. Create a virtual environment

```sh
python -m venv .venv
```

2. Activate the environment

```sh
source .venv/bin/activate
```

3. Install the required packages from `requirements.txt`

```sh
pip install -r requirements.txt
```

## Running

To run this example use

```sh
flask run
```
40 changes: 40 additions & 0 deletions examples/flask/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from flask import Flask, g, jsonify, request

from vqueue import TokenVerifier
from vqueue.exceptions import VQueueError

app = Flask(__name__)


def get_token_verifier() -> TokenVerifier:
"""
Gets the TokenVerifier from the global context of the app.
It's a good practice in order to reuse connections.
"""
if "VQueueTokenVerifier" not in g:
g.VQueueTokenVerifier = TokenVerifier()

return g.VQueueTokenVerifier


# Verify the token at root path, this expects a `token` query param
@app.route("/")
def hello():
token = request.args.get("token")

# Get the token verifier from the global context
token_verifier = get_token_verifier()
if token:
try:
# Call the `TokenVerifier.verify_token` method
verification_result = token_verifier.verify_token(token)

# If the verification is successful you can continue with your app's logic
return jsonify(verification_result)
except VQueueError as e:
# In case of an un successful verification, there will be an
# exception for you to handle. You can be more specific with the
# handling of the distinct exceptions that the method can raise
return jsonify({"success": False, "message": e.__dict__})

return jsonify({"success": False, "message": "No token parameter was given"}), 404
2 changes: 2 additions & 0 deletions examples/flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vqueue-sdk
Flask
Loading