{"id":34095708,"url":"https://github.com/fastpdfservices/fastpdf-python","last_synced_at":"2026-04-08T17:32:14.222Z","repository":{"id":180739562,"uuid":"659206317","full_name":"fastpdfservices/fastpdf-python","owner":"fastpdfservices","description":"Python SDK for Fast PDF Service ","archived":false,"fork":false,"pushed_at":"2024-01-05T14:09:02.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-16T19:12:12.183Z","etag":null,"topics":["html-to-pdf","pdf-converter","pdf-document-processor","pdf-generation"],"latest_commit_sha":null,"homepage":"https://fastpdfservice.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastpdfservices.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-06-27T10:49:11.000Z","updated_at":"2023-11-14T12:03:41.000Z","dependencies_parsed_at":"2023-11-14T13:25:07.428Z","dependency_job_id":"2819ffd6-844e-41a6-9a61-fa89974fbd8d","html_url":"https://github.com/fastpdfservices/fastpdf-python","commit_stats":null,"previous_names":["fastpdfservices/fastpdf-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fastpdfservices/fastpdf-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastpdfservices%2Ffastpdf-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastpdfservices%2Ffastpdf-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastpdfservices%2Ffastpdf-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastpdfservices%2Ffastpdf-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastpdfservices","download_url":"https://codeload.github.com/fastpdfservices/fastpdf-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastpdfservices%2Ffastpdf-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31566813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-to-pdf","pdf-converter","pdf-document-processor","pdf-generation"],"created_at":"2025-12-14T15:18:17.081Z","updated_at":"2026-04-08T17:32:14.214Z","avatar_url":"https://github.com/fastpdfservices.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Documentation Status](https://readthedocs.org/projects/fastpdf/badge/?version=latest)](https://fastpdf.readthedocs.io/en/latest/?badge=latest)\n[![PyPI version](https://img.shields.io/pypi/v/fastpdf.svg)](https://pypi.org/project/fastpdf/)\n\n# FastPDF Python Package\n\nWelcome to **fastpdf** Python Package, the versatile and quick solution for your PDF rendering needs. This package is a SDK for fastpdfservice.com REST API.\n\n## Overview\n\n`fastpdf` is a Python package designed to simplify the PDF generation process. It streamlines the procedure of rendering HTML/CSS templates into a PDF document, offering granular control over the rendering options, and provides the ability to add images and barcodes into your PDFs.\n\n`fastpdf` leverages the PDF manipulation API available at [https://fastpdfservice.com](https://fastpdfservice.com), ensuring high performance, scalability, and reliability. By using fastpdf, you are able to generate complex, high-quality PDFs efficiently. \n\n## Key Features\n\n1. **HTML/CSS to PDF**: Render your HTML/CSS templates into a PDF with ease and precision.\n2. **Header/Footer Management**: Easily manage the header and footer of your documents with flexible rendering options.\n3. **Barcode \u0026 Image Integration**: Seamlessly integrate images and barcodes into your PDFs.\n4. **Render Options**: Advanced render options allow granular control over your output. Control aspects like margins, orientation, scales, etc.\n5. **Image Mode Selection**: fastpdf supports various image modes to tailor the image rendering to your needs.\n\n## Getting Started\n\nBefore you start with the fastpdf Python Package, make sure you have Python 3.7+ installed on your machine.\n\nTo use `fastpdf`, you'll first need to register an account to [https://fastpdfservice.com](https://fastpdfservice.com), and get your API key. \n\nInstall fastpdf using pip:\n```shell\npip install fastpdf\n```\n\nImport the package in your Python script:\n\n```python\nfrom fastpdf import PDFClient\n```\n\nTo start with, make sure you have your FastPDF service API token handy. \nThis is required for all API calls to the FastPDF service. You can find your token under API settings in \nyour [FastPDF profile](https://fastpdfservice.com/profile/api).\n\n\u003cCodeGroup title=\"Register your token\"\u003e\n\n```python {{ title: 'Python' }}\nclient = PDFClient(\"API_KEY\")\n```\n\n\u003c/CodeGroup\u003e\n\n\nPlease refer to the [documentation](https://docs.fastpdfservice.com) for more details on the available features.\n\n\n## Creating a Basic Template\n\nCreating a basic template is simple. Let's start by creating an HTML document with a placeholder for a `name` variable.\nThen, you'll need to create a [Template](https://docs.fastpdfservice.com/templates#template) object and set `name` and `format`.\n\n\n\u003cCodeGroup title=\"Creating a basic template\"\u003e\n\n```python {{ title: 'Python' }}\nfrom fastpdf import Template\n\ntemplate_str = \"\u003chtml\u003e\u003cbody\u003eHello world, my name is {{name}}!\u003c/body\u003e\u003c/html\u003e\".encode()\ntemplate_data = Template(name=\"basic-document\", format=\"html\")\ntemplate = client.add_template(template_str, template_data)\n```\n\n\u003c/CodeGroup\u003e\n\n\u003cNote\u003e\n  *Make sure you do not forget to `encode()` your string. Otherwise, the string will be interpreted as a filename.*\n\u003c/Note\u003e\n\nIn this template, `{{name}}` is a placeholder that will be replaced by a real value when generating a PDF. \n\n## Your First Rendering\n\nNow, let's bring our document to life. We've got our template id handy, and our data ready to be cast into the chosen template. \nBut don't worry if you've misplaced the template id - a quick detour to your [template dashboard](https://fastpdfservice.com/services/templates) will point you right to it.\nIn our data object, we set a value for the `name` variable that we defined in our template.\n\n\u003cCodeGroup title=\"Rendering our basic template\"\u003e\n\n```python {{ title: 'Python' }}\ndocument_data = { 'name': 'John' }\n\ntemplate_id = template[\"id\"]\ndocument = client.render_template(template_id, document_data)\n```\n\n\u003c/CodeGroup\u003e\n\nFinally, we save it to the disk using the `save()` convenience function.\n\n\u003cCodeGroup title=\"Saving our document to the disk\"\u003e\n\n```python {{ title: 'Python' }}\nclient.save(document, \"path/to/basic-document.pdf\")\n```\n\n\u003c/CodeGroup\u003e\n\nAnd that's it! You've just brought your first PDF to life.\n\n\n## For Loops\n\nFastPDF allows for more complex templates. For instance, you can use control structures like for loops and if statements in your templates.\nHere is how to iterate over a list of items, using a for loop.\n\n\u003cCodeGroup title=\"For Loop\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_content = \"\"\"\n\u003chtml\u003e\n\u003cbody\u003e\n    \u003cul\u003e\n    {% for item in items %}\n        \u003cli\u003e{{ item }}\u003c/li\u003e\n    {% endfor %}\n    \u003c/ul\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\".encode()\ntemplate_data = Template(name=\"for-loop-document\", format=\"html\")\ntemplate = client.add_template(template_content, template_data)\n```\n\n\u003c/CodeGroup\u003e\n\nIn this template, `{% for item in items %}` starts the loop, and `{% endfor %}` ends it.\n\nNext, we define our rendering_data by associating a list of item value to the `items` key, and render our document.\n\n\u003cCodeGroup title=\"Rendering our For Loop template\"\u003e\n\n```python {{ title: 'Python' }}\ndocument_data = { 'items': [\"First item\", \"Second item\", \"Last item\"] }\n\ntemplate_id = template[\"id\"]\ndocument = client.render_template(template_id, document_data)\n# Save to disk, if needed\nclient.save(document, \"path/to/loop-document.pdf\")\n```\n\n\u003c/CodeGroup\u003e\n\n\n## If Statements\n\nIf statements can be used to conditionally include parts of the template, based on the rendering data. Here's an example:\n\n\u003cCodeGroup title=\"If statement\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_content = \"\"\"\n\u003chtml\u003e\n\u003cbody\u003e\n    {% if user_premium %}\n        \u003cp\u003eWelcome, premium user!\u003c/p\u003e\n    {% else %}\n        \u003cp\u003eWelcome, regular user!\u003c/p\u003e\n    {% endif %}\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\".encode()\ntemplate_data = Template(name=\"if-document\", format=\"html\")\ntemplate = client.add_template(template_content, template_data)\n```\n\n\u003c/CodeGroup\u003e\n\nIn this example, `{% if user_premium %}` starts the if statement, and `{% endif %}` ends it. \nIf `user_premium` is true, the \"Welcome, premium user!\" message will be included in the generated PDF. \nOtherwise, the \"Welcome, regular user!\" message will be included.\n\n## Stylesheets\n\n\u003cNote\u003e\n    *Please ensure that your stylesheets are written purely in CSS. As of now, FastPDF does not support precompiled CSS languages \n    like SCSS, or CSS frameworks like Tailwind. \n    Stick to standard CSS to ensure compatibility and successful rendering.*\n\u003c/Note\u003e\n\nYou can do this in one of two ways: by using a separate stylesheet, or by using inline CSS. \n\nThe latter works as usual, by either\nsetting the `style` property html tags, or by writing your css classes in the header of the template:\n\n\u003cCodeGroup title=\"A template with style\"\u003e\n\n```html {{ title: 'HTML' }}\n\u003chtml\u003e\n\u003chead\u003e\n    my-class {\n        color: #f43f54;\n        font-size: 12px;\n        font-weight: bold;\n    }\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cp class='my-class'\u003eWelcome, {{name}}!\u003c/p\u003e\n    \u003cp style='color: #ccc'\u003e Goodbye ! \u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003c/CodeGroup\u003e\n\nAlternatively, you can use the `add_stylesheet()` method to add a stylesheet to your template:\n\n\u003cCodeGroup title=\"A template with style\"\u003e\n\n```python {{ title: 'Python' }}\nfrom fastpdf import StylesheetFile\n\nstylesheet_path = \"styles.css\"\nstylesheet_data = StylesheetFile(format=\"css\")\n\ntemplate_id = template[\"id\"]\nclient.add_stylesheet(template_id, stylesheet_path, stylesheet_data)\n```\n\n\u003c/CodeGroup\u003e\n\nYour template will now be rendered with style !\n\n## Adding an image\n\nFastPDF allows you to add images to your templates, which can then be rendered into your final PDF documents. Here's how you can accomplish this.\n\nTo begin, we create our template with an `\u003cimg\u003e` tag, using our image uri in the `src` property as followed:\n\n\u003cCodeGroup title=\"Creating a template with an image\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_content = \"\"\"\n\u003chtml\u003e\n\u003cbody\u003e\n    \u003cimg src=\"{{my_favourite_logo}}\"\u003e\n    \u003cp\u003eWelcome, {{name}}!\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\".encode()\ntemplate_data = Template(name=\"image-document\", format=\"html\")\ntemplate = client.add_template(template_content, template_data)\n```\n\n\u003c/CodeGroup\u003e\n\nThen, we add an image to our template, and set the same image uri. \nThis step can be done from your [template dashboard](https://fastpdfservice.com/services/templates).\n\n\u003cCodeGroup title=\"Adding an image\"\u003e\n\n```python {{ title: 'Python' }}\nfrom fastpdf import ImageFile\n\nimage_path=\"my-logo.png\"\nimage_data = ImageFile(format=\"png\", uri=\"my_favourite_logo\")\ntemplate_id = template[\"id\"]\nres = client.add_image(template_id, image_path, image_data)\n```\n\n\u003c/CodeGroup\u003e\n\nFinally, we render our document. As usual, we define our rendering data object with our variable. \n\n\u003cCodeGroup title=\"Rendering our image template\"\u003e\n\n```python {{ title: 'Python' }}\nfrom fastpdf import ImageFile\n\nimage_path=\"my-logo.png\"\nimage_data = ImageFile(format=\"png\", uri=\"my_favourite_logo\")\n\ntemplate_id = template[\"id\"]\nres = client.add_image(template_id, image_path, image_data)\n```\n\n\u003c/CodeGroup\u003e\n\n## Custom Header and Footer\n\nBy default, FastPDF will include a header, composed of the document title and the date, and a footer with page numbers. \nYou can turn them on and off separately when adding your [Template](https://docs.fastpdfservice.com/templates#template) or during rendering with the \n[RenderOptions](https://docs.fastpdfservice.com/render#render-options).\n\nIt is also possible to add custom headers and footers to your PDF documents. These headers and footers can include images, and\ndynamic content such as the current page number, total number of pages, and the current date. Let's take a look at how to do this.\n\nFirstly, let's create a new template:\n\n\u003cCodeGroup title=\"A simple template\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_content = \"\"\"\n\u003chtml\u003e\n\u003cbody\u003e\n    \u003ch1\u003e{{title}}\u003c/h1\u003e\n    \u003cp\u003e{{content}}\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\".encode()\ntemplate_data = Template(name=\"customer-header-footer-document\", format=\"html\")\n```\n\n\u003c/CodeGroup\u003e\n\nYou might have noticed that we have not added the template yet. It is because we need to define our header and footer first.\nHeaders and footers comes with [special HTML classes](https://docs.fastpdfservice.comtemplates#header-and-footer) that can be used to inject printing values into them.\nWe will use them to set the page number.\n\n\n\u003cCodeGroup title=\"Custom header and footer\"\u003e\n\n```python {{ title: 'Python' }}\nheader_content = \"\"\"\n\u003cdiv style=\"text-align: center; padding: 10px; font-size: 8px;\"\u003e\n    \u003ch2\u003e{{header_note}}\u003c/h2\u003e\n\u003c/div\u003e\n\"\"\".encode()\nfooter_content = \"\"\"\n\u003cdiv style=\"text-align: center; margin: auto; padding: 10px; font-size: 8px;\"\u003e\n    \u003cspan class=\"pageNumber\"\u003e\u003c/span\u003e\n\u003c/div\u003e\n\"\"\".encode()\ntemplate = client.add_template(template_content, template_data, \n                               header_data=header_content, \n                               footer_data=footer_content)\n```\n\n\u003c/CodeGroup\u003e\n\nNow, when you render the PDF, pass the `header_note`, `title` and `content` in your data:\n\n\u003cCodeGroup title=\"Rendering custom header document\"\u003e\n\n```python {{ title: 'Python' }}\ndocument_data = { \n    'title': \"My document\",  \n    'content': \"My document content\",  \n    'header_note': \"This is my favorite header\",  \n}\n\ntemplate_id = template[\"id\"]\ndocument = client.render_template(template_id, document_data)\n# Save to disk, if needed\nclient.save(document, \"path/to/custom-header-document.pdf\")\n```\n\n\u003c/CodeGroup\u003e\n\n\n## Generating Multiple PDFs\n\nThe FastPDF API also provides the ability to generate multiple PDFs in a single API call. This feature, referred to as batch processing, can be useful in situations where you need to generate many PDFs with different data.\n\nThe way batch processing works in FastPDF is that you provide an array of data objects, each of which corresponds to one PDF. Let's see how to do this in practice.\n\nFirst, let's prepare our template and data. Suppose we want to generate PDFs for each user in our system.\n\n\u003cCodeGroup title=\"Basic template\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_content = \"\"\"\n\u003chtml\u003e\n\u003cbody\u003e\n    \u003ch1\u003eWelcome, {{name}}!\u003c/h1\u003e\n    \u003cp\u003eEmail: {{email}}\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\"\"\".encode()\ntemplate_data = Template(name=\"image-document\", format=\"html\")\ntemplate= client.add_template(template_content, template_data)\n```\n\n\u003c/CodeGroup\u003e\n\nHere, the template contains placeholders for user data (name and email). Next, we will prepare our data array.\nEach element of the array corresponds to one document. Here we will render 3 documents.\n\n\u003cCodeGroup title=\"List of data objects\"\u003e\n\n```python {{ title: 'Python' }}\nusers = [\n    {\"name\": \"John Doe\", \"email\": \"john@example.com\"},\n    {\"name\": \"Jane Doe\", \"email\": \"jane@example.com\"},\n    {\"name\": \"Richard Roe\", \"email\": \"richie@example.com\"},\n]\n```\n\n\u003c/CodeGroup\u003e\n\nFinally, we can call the `render_template_many()` method with our template id and batch data.\n\n\u003cCodeGroup title=\"Rendering of multiple Documents\"\u003e\n\n```python {{ title: 'Python' }}\ntemplate_id = template[\"id\"]\nzip_result = client.render_template_many(template_id, users)\n```\n\n\u003c/CodeGroup\u003e\n\nThe `render_template_many()` method will return a zip file that contains the 3 PDFs. \nYou now have the choice between extracting the zip_result into a python list, or in a directory on your disk, both using the `extract()` method.\n\n\u003cCodeGroup title=\"Extracting result PDFs\"\u003e\n\n```python {{ title: 'Python' }}\n# Save pdfs to the disk\nclient.extract(zip_result, \"path/to/directory/\")\n\n# Or get a list of PDF\npdfs = client.extract(zip_result)\n```\n\u003c/CodeGroup\u003e\n\n\n\n## Support\n\nFor any questions or support, reach out to us at `support@fastpdfservice.com`.\n\n## License\n\nfastpdf Python Package is licensed under the MIT license. See LICENSE for more details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastpdfservices%2Ffastpdf-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastpdfservices%2Ffastpdf-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastpdfservices%2Ffastpdf-python/lists"}