Skip to main content

No project description provided

Project description

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 ID
  • Client 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.

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

pavlok-0.1.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pavlok-0.1.4-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file pavlok-0.1.4.tar.gz.

File metadata

  • Download URL: pavlok-0.1.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pavlok-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e56612556838f70064afd554b94b4c8b297a330d99bba664334b3e48a995291e
MD5 798225e9b61d655cb9eff09ce3caeaed
BLAKE2b-256 8abd1e20053a72547033f4d496739b912a1ee6ed32703d3ebf5d9f127a7f60f1

See more details on using hashes here.

File details

Details for the file pavlok-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pavlok-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pavlok-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9bd7b16aa3dad04c5c5451f30f0b31c54a715a325a23a012fada0def39dfc5eb
MD5 664f2ffdcdc1352e69ad7e50108ade84
BLAKE2b-256 d5493977071a8abccdd7dac53946ad6e638d72b26de01e4f941a8b88757a2998

See more details on using hashes here.

Supported by

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