Get started with the Apryse Server SDK Python PDF library integration

This get-started guide explains how to set up your Python environment and install and use the Apryse Server SDK in a Python application. We'll demonstrate how to build a simple app for programmatic PDF generation.

There are two ways to use Apryse with Python:

  • Use pip to install third‑party Python packages, such as the Apryse SDK. The SDK is distributed as a precompiled Python library.
  • Use PDFNet bindings to build your own custom Python wrapper (less common).

This guide walks you through getting started with the precompiled Python SDK using pip.

Choose your preferred platform from these tabs.

Prerequisites

Before you start:

  • Install Visual Studio Code or another code editor to develop and debug code.
  • Install Python 3 and pip. In this guide, we use Homebrew to manage the Python installation.
  • Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Contact sales to purchase a commercial license key.

Keep your commercial license key confidential.

License keys are uniquely generated and strictly confidential. Don't publish or store them in any public location, including public GitHub repositories.

1. Set up Python and pip

Before getting started, ensure that Python and pip are installed. You’ll use pip to install the Apryse Server SDK.

Info

macOS includes a system‑managed Python used by the operating system. For development, install Python via Homebrew and use it inside a virtual environment.

  1. Check whether Python and pip are installed:

Bash

1python3 --version
2python3 -m pip --version
3which python3

The python3 path should point to Homebrew (for example, /opt/homebrew/bin/python3 or /usr/local/bin/python3). If it points to /usr/bin/python3, you're using the system Python.

2. If Python and pip aren't installed, install them with Homebrew. This command installs the latest Python version with pip:

Bash

1brew install python

3. If Python and pip are installed with Homebrew, update Homebrew and Python. This also updates pip:

Bash

1brew update
2brew upgrade python

2. Set up your project

Set up your project by creating a folder and preparing your workspace for the application.

  1. Go to your Documents folder and create a new NewApryseProject folder.
  2. In Visual Studio Code or your preferred editor, go to File > Open Folder.
  3. Find the NewApryseProject folder and click to Open in Visual Studio Code.
  4. Create a HelloWorld.py file at the root of your project.

3. Add the Apryse SDK

Next, integrate the Apryse Server SDK into your Python application and add the code needed to generate a PDF.

  1. Navigate to the ~/Documents/NewApryseProject directory in your terminal, then install the Apryse SDK using pip to fetch the package from Apryse's package index:

Info

Install the Apryse SDK in a virtual environment to ensure it's isolated and installed in a predictable location. When running Python scripts that import apryse-sdk, make sure you activate the same virtual environment first.

Bash

1python3 -m pip install apryse-sdk --extra-index-url=https://pypi.apryse.com

A successful output looks like:

Bash

1Looking in indexes: https://pypi.org/simple, <additional index>
2Collecting apryse-sdk
3 Downloading apryse_sdk-<version>.whl
4Installing collected packages: apryse-sdk
5Successfully installed apryse-sdk-<version>

Info

The legacy PDFNetPython3 package on the default Python Package Index (PyPI) is no longer maintained.

2. Open the HelloWorld.py file in Visual Studio Code or your preferred code editor:

Text

1~/Documents/NewApryseProject/HelloWorld.py

3. Add this code to the HelloWorld.py file, update your license key, and save your changes:

Python

HelloWorld.py

1# You can add the following line to integrate apryse-sdk
2# into your solution from anywhere on your system as long as
3# the library was installed successfully via pip
4
5from apryse_sdk import *
6
7def main():
8
9 # Initialize Apryse SDK
10 # Replace with your demo license key
11 PDFNet.Initialize("YOUR_LICENSE_KEY")
12
13 # This example creates a new document
14 # and a new page, then adds the page
15 # in the page sequence of the document
16 doc = PDFDoc()
17
18 page1 = doc.PageCreate()
19 doc.PagePushBack(page1)
20
21 # Save the document in a linearized
22 # format which is the most popular and
23 # effective way to speed up viewing PDFs
24 doc.Save(("output.pdf"), SDFDoc.e_linearized)
25
26 doc.Close()
27
28if __name__ == "__main__":
29 main()

Info

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.

With this code, you can:

  • Import and initialize the Apryse Python SDK using your license key.
  • Create a new PDF document and add a blank page.
  • Save the document as a linearized PDF for optimized viewing.
  • Perform document operations using the PDFNet API—in this case, creating and modifying a PDFDoc object.
  • Close the document after saving.

4. Verify your output

Finally, build and run your application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally.

  1. From the terminal, in the NewApryseProject folder, run the HelloWorld.py script:

Bash

1python3 -u HelloWorld.py

A successful output looks similar to:

Bash

1PDFNet is running in demo mode.
2PackageV2: base

2. Navigate to the Documents > NewApryseProject folder.

3. Verify the blank output.pdf file was generated programmatically using the Apryse Server SDK. The folder structure looks similar to:

Text

1NewApryseProject/
2├── HelloWorld.py
3└── output.pdf

Related Blogs

How to Build Optical Character Recognition (OCR) in Python - 1/16/25

Splitting a PDF Using Python - 9/11/24

PDF to Office Document Conversion Using Apryse and Python - 4/4/24

Generating Documents and Reports from DOCX Templates and JSON using Apryse and Python - 10/9/23

A Guide to PDF Data Extraction Using Apryse SDK and Python - 7/20/23

Adding a Digital Signature to a PDF With the Python SDK - 7/13/23

How to Extract Text from a PDF Using Python - 12/9/22

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales