Pritunl API Client for Python 3
This is a simple Pritunl API Client written in Python 3.
You need to refer to Pritunl API Documentation to understand how to use this. This API client uses almost the same command as the API Handlers.
Installation
Install the published package using pip from our PyPI project repository.
pip install pritunl-api
Beyond the core API client library, we also added the executable distribution in this project. Add extra cli during the PIP installation to enable the CLI feature.
pip install pritunl-api[cli]
Proceed to the CLI Usage for the complete command options and syntax.
API Usage
Before using the API library including the use of the CLI feature, we need to provide the Pritunl API URL and administrative credentials in our environment variables.
export PRITUNL_BASE_URL="https://vpn.domain.tld/"
export PRITUNL_API_TOKEN="XXXXXXXXXXXXXXXXXXXXXX"
export PRITUNL_API_SECRET="XXXXXXXXXXXXXXXXXXXXX"
Initializing an API Instance.
# Import the object
from pritunl_api import Pritunl
# Create an instance
pritunl = Pritunl()
## You can also initialize an instance by manually providing the arguments.
# pritunl = Pritunl(
# url="<PRITUNL API URL>",
# token="<PRITUNL API TOKEN>",
# secret="<PRITUNL API SECRET>"
# )
# Your Pritunl API Client instance is now ready to use!
pritunl.<FEATURE>.<METHOD>
Example
-
Example 1:
(in source)
GET /serverpritunl.server.get()
-
Example 2:
(in source)
PUT /server/:server_id/organization/:organization_idpritunl.server.put(srv_id='', org_id='')
-
Example 3:
(in source)
DELETE /user/:organization_id/:user_idpritunl.user.delete(org_id='', usr_id='')
-
Example 4:
(in source)
POST /server**pritunl.server.post( data={ 'name': 'new server name' } )
- If there is data available, you must pass it through the data parameter.
- The command above works well because there are templates available for creating a new server.
-
Example 5:
(in source)
PUT /user/:organization_id/:user_idpritunl.user.put(org_id='', usr_id='', data={ 'name': 'modified org name', 'disabled': True } )
CLI Usage
Available Commands
As of this period of development, the feature is limited.
To show the available commands, use the help option.
pritunl-api-cli --help
Usage: pritunl-api-cli [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
create-user
delete-user
get-user
update-user
For available command options and syntax, use the feature command help option.
pritunl-api-cli create-user --help
Usage: pritunl-api-cli create-user [OPTIONS]
Options:
--org-name TEXT
--user-name TEXT
--user-email TEXT
--pin TEXT
--yubikey-id TEXT
--from-csv-file PATH
--help Show this message and exit.
Create User
Example 1: Create a Single User
pritunl-api-cli create-user \
--org-name develop-network \
--user-name developer_1 \
--user-email developer_1@domain.tld
Example 2: Create Users from CSV
pritunl-api-cli create-user \
--from-csv-file ./users.csv
Delete User
pritunl-api-cli delete-user \
--org-name develop-network \
--user-name developer_1
Get User Information
pritunl-api-cli get-user \
--org-name develop-network \
--user-name developer_1
Or get (regenerate) the profile key of a user
pritunl-api-cli get-user \
--org-name develop-network \
--user-name developer_1 \
--get-profile-key-only
Update a User
To disable a user
pritunl-api-cli update-user \
--org-name develop-network \
--user-name developer_1 \
--disable
To enable a user
pritunl-api-cli update-user \
--org-name developer-network \
--user-name developer_1 \
--enable
API Development
Using Virtual Environment
Create a virtual environment and activate it.
python -m venv ./venv
source ./venv/bin/activate
Or simple use other Python Version Manager like pyenv.
pip install -e .
Include REPL Tools
pip install -e .[repl]
ptipython
Using Docker Environment
Building a Development Container
docker buildx build . \
--progress plain \
--file dev.Dockerfile \
--tag pritunl-api:development
Running a Development Container
docker run --rm -it \
--volume $(PWD):/pritunl-api \
--env-file .env \
pritunl-api:development
This API client is not fully complete. Some features are missing, feel free to fork and pull requests to add new features.
Tested working on Pritunl v1.30.3354.99.
Release files for pritunl-api 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pritunl_api-1.1.5.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pritunl_api-1.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.0 kB
Release files / pritunl_api-1.1.5.tar.gz
| Download URL | pritunl_api-1.1.5.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9059743fcffd8b4978258387542de8f18fd7da36168d8b94c4624887878190f6
|
|
BLAKE2b-256 checksum How to use checksums |
5e17f04bd439cf8645e09d48d2ceff6a1e27a352b0986f7d010b17c18a180ee1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.11.2 Darwin/22.3.0
|
Release files / pritunl_api-1.1.5-py3-none-any.whl
| Download URL | pritunl_api-1.1.5-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f1c405ae18c0f328894c2f2596af4ebc4141c438d877469cda4ebe9f7defa00
|
|
BLAKE2b-256 checksum How to use checksums |
da2645444740b2adf68a2ed6f8fd989149d026882a9da717119d800e23045258
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.11.2 Darwin/22.3.0
|