Skip to main content

Pritunl API Client for Python

This is a simple Pritunl API Client written in Python.

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="<PRITUNL API TOKEN>"
export PRITUNL_API_SECRET="<PRITUNL API SECRET>"

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 BASE 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 /server

    pritunl.server.get()
    
  • Example 2:

    (in source) PUT /server/:server_id/organization/:organization_id

    pritunl.server.put(srv_id='', org_id='')
    
  • Example 3:

    (in source) DELETE /user/:organization_id/:user_id

    pritunl.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_id

    pritunl.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]...

  Pritunl API CLI

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  api
  user

To show the available commands for a feature

pritunl-api-cli user --help
Usage: pritunl-api-cli user [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  create
  delete
  get
  update

For available command options and syntax, use the feature command argument help option.

pritunl-api-cli user create --help
Usage: pritunl-api-cli user create [OPTIONS]

Options:
  --org-name TEXT
  --user-name TEXT
  --user-email TEXT
  --pin TEXT
  --yubikey-id TEXT
  --from-csv PATH
  --help             Show this message and exit.

Example 1: Create a Single User

pritunl-api-cli user create \
  --org-name pritunl-dev \
  --user-name john.doe \
  --user-email john.doe@domain.tld

Example 2: Create Users from CSV

pritunl-api-cli user create \
  --from-csv ./users.csv

For more CLI examples checkout the blog post Managing Enterprise VPN using Pritunl API CLI.

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.

Alternative API Clients

Metadata

Release files for pritunl-api 1.1.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pritunl-api 1.1.12
File Size Uploaded Provenance Actions
pritunl_api-1.1.12.tar.gz 11.1 kB Without provenance Details for pritunl_api-1.1.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pritunl-api 1.1.12
File Interpreter ABI Platform Actions
pritunl_api-1.1.12-py3-none-any.whl Python 3 none any Details for pritunl_api-1.1.12-py3-none-any.whl

Total release size: 22.8 kB

Release files / pritunl_api-1.1.12.tar.gz

Download URL pritunl_api-1.1.12.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
23c197150a244b8b8f55e65f94ad2621f22d79edb97fe11d8a8d9bc6155a6daf
BLAKE2b-256 checksum
How to use checksums
cd5a2162a1792b027a633a82e6aa8763095305f4bac84bcd4fafc4b33a8cf75b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

Release files / pritunl_api-1.1.12-py3-none-any.whl

Download URL pritunl_api-1.1.12-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3101b6d4fbaa19b736deeb779531bd2a089af7739574e42d066cf0cf71dfb770
BLAKE2b-256 checksum
How to use checksums
934256361a58202695cb7a2240cc11ed686e5f90391a265c9e5f73b75a67f289
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1018-azure

Security for pritunl-api 1.1.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page