Install GroupDocs.Assembly for Python via .NET and Apply License

Overview

Before you can start generating documents with GroupDocs.Assembly for Python via .NET, you need to install the package and apply a license. This guide shows you how to install the package from PyPI and configure licensing to remove evaluation limitations.

The main classes involved are:

Here are the steps to get started:

  • Install the groupdocs-assembly-net package with pip
  • Apply a license from a file or stream using the set_license method, or name the license file in the GROUPDOCS_LIC_PATH environment variable
  • Verify that the license is applied correctly before using DocumentAssembler
Note
Calling set_license multiple times is not harmful but wastes processor time. Call it once, at start-up: in a script, before the first assembly; in a web application, where the application is created (a Flask application factory, Django’s AppConfig.ready, a FastAPI startup handler).

Install from PyPI

The package is published on PyPI and bundles everything it needs, the .NET runtime included. Install it with pip:

pip install groupdocs-assembly-net

Then import it as groupdocs.assembly. See Installation and System Requirements for the supported platforms and Python versions.

Install a Specific Version

To pin a version, for instance in requirements.txt, name it:

pip install groupdocs-assembly-net==26.11.0

Apply License from File

After installation, apply your license file to remove evaluation limitations. The example reads the path from the GROUPDOCS_LIC_PATH environment variable and falls back to a GroupDocs.Assembly.lic file in the current folder. A relative path is resolved against the current working directory of the process, which may differ from your script’s folder (in a service or a web application), so an absolute path is recommended:

import os

from groupdocs.assembly import License

# Path to your license file
license_path = os.environ.get("GROUPDOCS_LIC_PATH", "GroupDocs.Assembly.lic")

# Apply the license
if os.path.exists(license_path):
    license = License()
    license.set_license(license_path)
    print("License applied successfully from file.")
else:
    print("License file not found. Running in evaluation mode.")
License applied successfully from file.

Download full output

Apply License from Stream

You can also load a license from any readable binary stream, which is handy when the license ships inside your application’s package:

import os

from groupdocs.assembly import License

license_path = os.environ.get("GROUPDOCS_LIC_PATH", "GroupDocs.Assembly.lic")

if os.path.exists(license_path):
    # Load license file into a stream
    with open(license_path, "rb") as stream:
        license = License()
        license.set_license(stream)
    print("License applied successfully from stream.")
else:
    print("License file not found. Running in evaluation mode.")
License applied successfully from stream.

Download full output

Apply License from an Environment Variable

Set GROUPDOCS_LIC_PATH to the license file’s path, or to a URL that serves it, and the license is applied at the first call into the engine, with no licensing code:

$env:GROUPDOCS_LIC_PATH = "C:\licenses\GroupDocs.Assembly.lic"
export GROUPDOCS_LIC_PATH="/opt/licenses/GroupDocs.Assembly.lic"

A license that cannot be applied this way (a missing file, an expired subscription, a license for another product) raises LicenseError from the first call into the engine on, rather than letting the process run in evaluation mode unnoticed. The message names the variable and the reason, for instance “GROUPDOCS_LIC_PATH=missing.lic could not be applied: the file does not exist”. Set GROUPDOCS_LIC_STRICT=0 to get a LicenseWarning and evaluation mode instead.

Verify License Application

The is_licensed property tells whether a license is applied. To be sure, generate a document and check that it has no evaluation watermark:

import os

from groupdocs.assembly import DataSourceInfo, DocumentAssembler, License

license_path = os.environ.get("GROUPDOCS_LIC_PATH", "GroupDocs.Assembly.lic")

license = License()
if os.path.exists(license_path):
    license.set_license(license_path)
print("Licensed:", license.is_licensed)

# Try to assemble a simple document
assembler = DocumentAssembler()
assembler.assemble_document("license-check.docx", "license-check-report.docx",
                            DataSourceInfo("Harbor Lane Provisions", "company"))
# If the license is valid, no evaluation watermark appears
print("License verification: check license-check-report.docx for a watermark.")

The following sample file is used in this example: license-check.docx

Binary file (DOCX, 7 KB)

Download full output

Apply a Metered License

A Metered License bills by usage. Pass your public and private keys to set_metered_key before using the API, then read the consumption. This code is not run with the documentation, because it needs your own keys; keys that are not valid raise RuntimeError (“Authentication failed.”):

import os

from groupdocs.assembly import Metered

public_key = os.environ["GROUPDOCS_METERED_PUBLIC_KEY"]
private_key = os.environ["GROUPDOCS_METERED_PRIVATE_KEY"]

# Apply the metered keys before assembling documents
metered = Metered()
metered.set_metered_key(public_key, private_key)

print("Consumption quantity:", Metered.get_consumption_quantity())
print("Consumption credit:", Metered.get_consumption_credit())
Warning
The license file contains a digital signature. Do not modify the license file, as even adding an extra line break will invalidate it.

“Cannot find license” Error

set_license with a path that does not exist raises FileNotFoundError (“Cannot find license ‘GroupDocs.Assembly.lic’.”). When you download the license, some web browsers append .xml to its name, and Windows hides known extensions by default, so GroupDocs.Assembly.lic.xml is shown as GroupDocs.Assembly.lic. Rename the file to remove the .xml extension. You are not required to keep the name GroupDocs.Assembly.lic: rename the file as you like and pass that name.

Advanced Usage Topics

To learn more about the evaluation limitations and the licensing options, please refer to Evaluation Limitations and Licensing and the advanced usage section.

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured library, we provide simple but powerful free online apps.

To assemble documents from templates and data sources, you can use the online apps from the GroupDocs.Assembly App Product Family.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.