# IronPDF for Python - Create, Edit, and Read PDFs in Python Scripts
## Introduction to IronPDF for Python
IronPDF for Python is a powerful library developed by Iron Software, offering software engineers the capability to create, edit, and extract PDF content in Python 3 projects.
`IronPDF for Python` builds upon the success and popularity of [IronPDF for .NET](/).
<div class="hsg-featured-snippet">
<h2>Key Features of IronPDF for Python:</h2>
<ol>
<li><a class="js-modal-open" data-modal-id="download-modal" href="#download-modal">Generate PDFs from HTML, URLs, JavaScript, CSS, and various image formats</a></li>
<li>Add headers/footers, signatures, attachments, and passwords and security to PDFs</li>
<li>Optimize performance from full multithreading and asynchronous support</li>
<li>Explore our website to discover a comprehensive list of over 50 features and access numerous code examples</li>
</ol>
</div>
## Using IronPDF for Python
### Prerequisites
To use IronPDF for Python, please ensure that the computer has the following prerequisite software installed:
1. **.NET 6.0 SDK:** IronPDF for Python relies on the IronPDF .NET library, specifically .NET 6.0, as its underlying technology. Therefore, it is necessary to have the [.NET 6.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) installed on your machine to use IronPDF for Python.
2. **Python:** Download and install the latest version of Python 3.x from the official Python website: https://www.python.org/downloads/. During the installation process, make sure to select the option to add Python to the system PATH, which will make it accessible from the command line.
3. **Pip:** Pip is usually bundled with Python installations starting from Python 3.4 and later. However, depending on your Python installation, you may need to check if pip is already installed or install it separately.
4. **IronPDF Library:** The IronPDF library can be added via pip. Use the command below to install IronPDF using pip:
```shell
:ProductInstall
```
[[t:(To install a specific version of IronPDF, please use the following syntax: "==2023.x.x". For example, you can run the command "pip install IronPDF==2023.x.x".)]]
[[i:(On some systems, Python 2.x may still be the default version. In such cases, you may need to explicitly use the `pip3` command instead of `pip` to ensure that you're using pip for Python 3.)]]
**Potential Installation Issues**
For either of the issues below, refer to the troubleshooting articles to resolve them:
- [Could not install packages due to an OSError](/python/troubleshooting/could-not-install-package/)
- [Failed to locate IronPdf.Slim.dll](/python/troubleshooting/failed-to-locate-ironpdf/)
## Start writing Python code
Import the necessary modules for PDF document generation and manipulation by using the statement below. Make sure to import them at the top of your Python script.
```python
# Import necessary components from the IronPDF library
from ironpdf import *
```
### Applying License Key
Next, apply a valid license or trial key to IronPDF by assigning the license key to the **LicenseKey** attribute of **License** object. Include the following code right after the import statement, before using any IronPDF methods:
```python
# Apply the license key for IronPDF
License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"
```
[[i:(Ensure that all settings, logging, and licensing operations are performed before calling any IronPDF methods.)]]
### Render HTML to PDF
Utilize the `RenderHtmlAsPdf` method to convert an HTML string into a PDF document. The code below converts a simple HTML string to a PDF document:
```python
from ironpdf import *
# Instantiate ChromePdfRenderer
renderer = ChromePdfRenderer()
# Create a PDF from an HTML string
pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
# Save the generated PDF to a file
pdf.SaveAs("html_to_pdf.pdf")
```
### Convert URL to PDF
Use the `RenderUrlAsPdf` method to convert a URL or local file path to a PDF document. Here's an example:
```python
from ironpdf import *
# Instantiate ChromePdfRenderer
renderer = ChromePdfRenderer()
# Create a PDF from a URL or local file path
pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
# Save the generated PDF to a file
pdf.SaveAs("url_to_pdf.pdf")
```
### Logging
To enable logging, use the following code snippets:
```python
# Enable debugging for logging
Logger.EnableDebugging = True
# Specify the log file path
Logger.LogFilePath = "Default.log"
# Set the logging mode to log all activities
Logger.LoggingMode = Logger.LoggingModes.All
```
## Licensing & Support Available
[Purchase a license](/python/licensing/) to use in live projects. 30-day trial licenses are also available [here](trial-license)
For our full list of code examples, tutorials, licensing information, and documentation visit: [IronPDF for Python](/python/).
For more support and inquiries, please [ask our team](#live-chat-support).
IronPDF for Python is a powerful library developed by Iron Software, offering software engineers the capability to create, edit, and extract PDF content in Python 3 projects.
IronPDF for Python builds upon the success and popularity of IronPDF for .NET.
Add headers/footers, signatures, attachments, and passwords and security to PDFs
Optimize performance from full multithreading and asynchronous support
Explore our website to discover a comprehensive list of over 50 features and access numerous code examples
Using IronPDF for Python
Prerequisites
To use IronPDF for Python, please ensure that the computer has the following prerequisite software installed:
.NET 6.0 SDK: IronPDF for Python relies on the IronPDF .NET library, specifically .NET 6.0, as its underlying technology. Therefore, it is necessary to have the .NET 6.0 SDK installed on your machine to use IronPDF for Python.
Python: Download and install the latest version of Python 3.x from the official Python website: https://www.python.org/downloads/. During the installation process, make sure to select the option to add Python to the system PATH, which will make it accessible from the command line.
Pip: Pip is usually bundled with Python installations starting from Python 3.4 and later. However, depending on your Python installation, you may need to check if pip is already installed or install it separately.
IronPDF Library: The IronPDF library can be added via pip. Use the command below to install IronPDF using pip:
> pip install ironpdf
pip install ironpdf
Tips: To install a specific version of IronPDF, please use the following syntax: "==2023.x.x". For example, you can run the command "pip install IronPDF==2023.x.x".
Please note: On some systems, Python 2.x may still be the default version. In such cases, you may need to explicitly use the pip3 command instead of pip to ensure that you're using pip for Python 3.
Potential Installation Issues
For either of the issues below, refer to the troubleshooting articles to resolve them:
Import the necessary modules for PDF document generation and manipulation by using the statement below. Make sure to import them at the top of your Python script.
# Import necessary components from the IronPDF libraryfrom ironpdf import *
# Import necessary components from the IronPDF library
from ironpdf import *
Python
Applying License Key
Next, apply a valid license or trial key to IronPDF by assigning the license key to the LicenseKey attribute of License object. Include the following code right after the import statement, before using any IronPDF methods:
# Apply the license key for IronPDFLicense.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"
# Apply the license key for IronPDF
License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"
Python
Please note: Ensure that all settings, logging, and licensing operations are performed before calling any IronPDF methods.
Render HTML to PDF
Utilize the RenderHtmlAsPdf method to convert an HTML string into a PDF document. The code below converts a simple HTML string to a PDF document:
from ironpdf import *# Instantiate ChromePdfRendererrenderer = ChromePdfRenderer()# Create a PDF from an HTML stringpdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")# Save the generated PDF to a filepdf.SaveAs("html_to_pdf.pdf")
from ironpdf import *
# Instantiate ChromePdfRenderer
renderer = ChromePdfRenderer()
# Create a PDF from an HTML string
pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
# Save the generated PDF to a file
pdf.SaveAs("html_to_pdf.pdf")
Python
Convert URL to PDF
Use the RenderUrlAsPdf method to convert a URL or local file path to a PDF document. Here's an example:
from ironpdf import *# Instantiate ChromePdfRendererrenderer = ChromePdfRenderer()# Create a PDF from a URL or local file pathpdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")# Save the generated PDF to a filepdf.SaveAs("url_to_pdf.pdf")
from ironpdf import *
# Instantiate ChromePdfRenderer
renderer = ChromePdfRenderer()
# Create a PDF from a URL or local file path
pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
# Save the generated PDF to a file
pdf.SaveAs("url_to_pdf.pdf")
Python
Logging
To enable logging, use the following code snippets:
# Enable debugging for loggingLogger.EnableDebugging = True# Specify the log file pathLogger.LogFilePath = "Default.log"# Set the logging mode to log all activitiesLogger.LoggingMode = Logger.LoggingModes.All
# Enable debugging for logging
Logger.EnableDebugging = True
# Specify the log file path
Logger.LogFilePath = "Default.log"
# Set the logging mode to log all activities
Logger.LoggingMode = Logger.LoggingModes.All
Python
Licensing & Support Available
Purchase a license to use in live projects. 30-day trial licenses are also available here
For our full list of code examples, tutorials, licensing information, and documentation visit: IronPDF for Python.
For more support and inquiries, please ask our team.
Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.