Install GroupDocs.Assembly for Python via .NET and Apply License
Leave feedback
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.
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:
importosfromgroupdocs.assemblyimportLicense# Path to your license filelicense_path=os.environ.get("GROUPDOCS_LIC_PATH","GroupDocs.Assembly.lic")# Apply the licenseifos.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.")
You can also load a license from any readable binary stream, which is handy when the license ships inside your application’s package:
importosfromgroupdocs.assemblyimportLicenselicense_path=os.environ.get("GROUPDOCS_LIC_PATH","GroupDocs.Assembly.lic")ifos.path.exists(license_path):# Load license file into a streamwithopen(license_path,"rb")asstream:license=License()license.set_license(stream)print("License applied successfully from stream.")else:print("License file not found. Running in evaluation mode.")
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:
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:
importosfromgroupdocs.assemblyimportDataSourceInfo,DocumentAssembler,Licenselicense_path=os.environ.get("GROUPDOCS_LIC_PATH","GroupDocs.Assembly.lic")license=License()ifos.path.exists(license_path):license.set_license(license_path)print("Licensed:",license.is_licensed)# Try to assemble a simple documentassembler=DocumentAssembler()assembler.assemble_document("license-check.docx","license-check-report.docx",DataSourceInfo("Harbor Lane Provisions","company"))# If the license is valid, no evaluation watermark appearsprint("License verification: check license-check-report.docx for a watermark.")
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.”):
importosfromgroupdocs.assemblyimportMeteredpublic_key=os.environ["GROUPDOCS_METERED_PUBLIC_KEY"]private_key=os.environ["GROUPDOCS_METERED_PRIVATE_KEY"]# Apply the metered keys before assembling documentsmetered=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.