Pavlok Python Client
Purpose
The Pavlok package makes it easy to play with your Pavlok device.
It works in two modes
- local development mode
- server mode
Local Mode
It can be used to play around with your device in a local development environment. It spins up a simple FastAPI server.
Server Mode
It can be used to plug the module into your existing express server and build features/workflows for your pavlok device.
Installation
Using pip
pip install pavlok
Setup
You would need two keys for the module to work
Client IDClient Secret
Navigate here and login with your Pavlok account to get one.
You'll need to choose a callback URL of http://localhost:8000/authorize for local mode.
Usage
First thing you'd need to do is import the module into your app.
from pavlok.main import Pavlok
The simplest and quickest way to start using the module is to try it in the local mode.
pavlok = Pavlok(
client_id=os.environ.get("client_id"),
client_secret=os.environ.get("client_secret"),
title="Pavlok Python Client",
)
pavlok.start()
This spins up a server on port 8000. (ex: http://localhost:8000/).
It initializes the Pavlok. Now you can login and start sending the stimuli to your device.
If you would like to configure a custom port for the local mode, you can do so by passing a custom options object as the third paramater to the init method. Make sure to mention the port in the callback URL of application you created here
pavlok = Pavlok(
client_id=os.environ.get("client_id"),
client_secret=os.environ.get("client_secret"),
title="Pavlok Python Client",
)
pavlok.start()
To Use the module in the server mode, you would need to pass a couple of more options in the the init method and ensure you call it before your server starts listening
pavlok = Pavlok(
client_id=os.environ.get("client_id"),
client_secret=os.environ.get("client_secret"),
title="Pavlok Python Client",
)
app = FastAPI(title=self.title, version="0.1.0")
app.add_middleware(SessionMiddleware, secret_key="secret")
@app.get("/authorize")
async def authorize(request: Request):
token = await pavlok.authorize(request)
user = self.get_user(request)
return token
Now that you are authenticated, you can start sending the stimuli to your Pavlok device from the server.
Stimuli methods for the server mode take a required parameter in the options object i.e. request. It is the request object that FastAPI gets when one of it's api is called. Stimuli methods expects an authorization token stored on the request object to verify the user.
So a simple call to one of the stimuli method would look like
@app.get("/vibrate")
@app.get("/vibrate/{strength}")
async def vibrate(request: Request, strength: str = "200"):
if self.token is None:
response = RedirectResponse(url="/login")
return response
stimuli_response = await self.vibrate(strength=strength)
return templates.TemplateResponse(
"index.html", {"request": request, "token": self.token,
"message": stimuli_response}, status_code=200
)
License
Licensed under the MIT license.
Release files for pavlok 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pavlok-0.1.4.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pavlok-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.7 kB
Release files / pavlok-0.1.4.tar.gz
| Download URL | pavlok-0.1.4.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e56612556838f70064afd554b94b4c8b297a330d99bba664334b3e48a995291e
|
|
BLAKE2b-256 checksum How to use checksums |
8abd1e20053a72547033f4d496739b912a1ee6ed32703d3ebf5d9f127a7f60f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / pavlok-0.1.4-py3-none-any.whl
| Download URL | pavlok-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bd7b16aa3dad04c5c5451f30f0b31c54a715a325a23a012fada0def39dfc5eb
|
|
BLAKE2b-256 checksum How to use checksums |
d5493977071a8abccdd7dac53946ad6e638d72b26de01e4f941a8b88757a2998
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|