nextpyp.client.Client#
- class nextpyp.client.Client#
Bases:
objectClient for the NextPYP website.
A complete listing of what services are available what services are available can be found at:
Servicesfor regular servicesRealtimeServicesfor realtime services
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 (
jeffin 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
Create a new client that can connect to the website at the given URL
Asks the nextPYP website for its API version number and compares it to the version number built into this client.
Attributes
The URL passed into
__init__The credentials, if any, passed into
__init__All of the services available with this client.
All of the realtime services available with this client.
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.orgIf a port is needed, include it with a colon:
http://nextpyp.my.org:8080credentials (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:
nonein 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
RealtimeServicesClass for a complete listing.
-
services:
Services# All of the services available with this client. See the
ServicesClass for a complete listing.
-
url_base:
str# The URL passed into
__init__