nextpyp.client.Client#

class nextpyp.client.Client#

Bases: object

Client for the NextPYP website.

A complete listing of what services are available what services are available can be found at:

Examples

Before the client can be fully used, your app must ask for permission from the NextPYP user. Start by requesting an app token by using the client in unauthenticated mode.

from nextpyp.client import Client

client = Client('https://nextpyp.my.org')
token_data = client.services.apps.request_token(
    user_id='jeff',
    app_name='My App',
    app_permission_ids=['project_list']
)
print(f'token data: {token_data}')

The above example will print output similar to the following.

AppTokenRequestData[request_id='the-request-id', app_name='My App', permissions=[AppPermissionData[...]]]

Once the token has been requested, the user (jeff in this example) should approve the request on the website and copy the app token into your app. The app token is just a string, so it should be easy to handle.

Once you have the app token, you can use the client in authenticated mode which allows access to the services on behalf of the user according to the assigned permissions.

client = Client(
    url_base='https://nextpyp.my.org',
    credentials=Credentials(
        userid='jeff',
        token='the-app-token'
    )
)
projects = client.services.projects.list('jeff')

Version Compatibility

The nextPYP publishes a SemVer version number to communicate compatibility information with clients.

It’s a good idea to check if your client version is compatible with the website API version before using it. This will help warn you if the website API has been updated with a breaking change, but the client hasn’t been updated to match yet.

client = Client('https://nextpyp.my.org')
if not client.is_compatible():
    raise Exception("Client might not work anymore, time to update")

Methods

__init__

Create a new client that can connect to the website at the given URL

is_compatible

Asks the nextPYP website for its API version number and compares it to the version number built into this client.

Attributes

url_base

The URL passed into __init__

credentials

The credentials, if any, passed into __init__

services

All of the services available with this client.

realtime_services

All of the realtime services available with this client.

api_version

The nextPYP API version this client was built against.

Details

__init__(url_base, credentials)#

Create a new client that can connect to the website at the given URL

Parameters:
  • url_base (str) –

    The base of the URL for your NextPYP website.

    Only the scheme and authority parts of the URL should be included, but not any path part.

    For example: https://nextpyp.my.org

    If a port is needed, include it with a colon: http://nextpyp.my.org:8080

  • credentials (Credentials | None) –

    The credentials, if any, to be used with this client.

    Omit this parameter to use the client in unauthenticated mode. Unauthenticated mode is only able to access a limited set of service functions. These service functions are marked as Permission Needed: none in the documentation.

Return type:

None

api_version: str#

The nextPYP API version this client was built against.

credentials: Optional[Credentials]#

The credentials, if any, passed into __init__

is_compatible()#

Asks the nextPYP website for its API version number and compares it to the version number built into this client. This client is compatible with the website if (and only if) the two major version numbers match and the client minor version is less than or equal to the server.

In this case, compatibility means that every service supported by the client is also supported by the server.

Return type:

bool

realtime_services: RealtimeServices#

All of the realtime services available with this client. See the RealtimeServices Class for a complete listing.

services: Services#

All of the services available with this client. See the Services Class for a complete listing.

url_base: str#

The URL passed into __init__