{"id":5701,"library":"pypdf2","title":"PyPDF2 (DEPRECATED: migrate to PyPDF)","description":"PyPDF2 is a pure-Python library designed for PDF file manipulation, offering capabilities like splitting, merging, cropping, and transforming PDF pages. The `pypdf2` package on PyPI, with its final major version 3.0.1, is now officially deprecated. It functions as a compatibility wrapper, internally using the API of `pypdf` version 3.0.1. All active development, new features, and security updates are happening under the `pypdf` project (currently at version 6.x.x), which is the recommended library for all new and ongoing PDF processing tasks in Python.","status":"deprecated","version":"3.0.1","language":"python","source_language":"en","source_url":"https://github.com/py-pdf/PyPDF2","tags":["pdf","document processing","deprecated","file manipulation"],"install":[{"cmd":"pip install pypdf2","lang":"bash","label":"Install deprecated PyPDF2 (wraps pypdf 3.0.1)"},{"cmd":"pip install pypdf","lang":"bash","label":"RECOMMENDED: Install active PyPDF library"},{"cmd":"pip install pypdf[crypto]","lang":"bash","label":"Install active PyPDF with AES encryption support"}],"dependencies":[{"reason":"Required for AES encryption and decryption if the 'crypto' extra is installed with pypdf.","package":"PyCryptodome","optional":true}],"imports":[{"wrong":"from pypdf import PdfReader","symbol":"PdfReader","correct":"from PyPDF2 import PdfReader"},{"wrong":"from pypdf import PdfWriter","symbol":"PdfWriter","correct":"from PyPDF2 import PdfWriter"}],"quickstart":{"code":"from pypdf import PdfReader, PdfWriter\nimport os\n\n# Create a dummy PDF for demonstration if it doesn't exist\ndummy_pdf_path = \"example.pdf\"\nif not os.path.exists(dummy_pdf_path):\n    writer = PdfWriter()\n    writer.add_blank_page(width=72, height=72)\n    writer.add_blank_page(width=72, height=72)\n    with open(dummy_pdf_path, \"wb\") as f:\n        writer.write(f)\n\n# --- Example: Read, extract text, and merge pages using pypdf (successor to PyPDF2) ---\n\n# Create a PdfReader object\nreader = PdfReader(dummy_pdf_path)\n\n# Get number of pages\nnum_pages = len(reader.pages)\nprint(f\"Number of pages: {num_pages}\")\n\n# Extract text from the first page\nfirst_page = reader.pages[0]\ntext = first_page.extract_text()\nprint(f\"Text from first page: '{text.strip() if text else 'No text'}'\")\n\n# Create a PdfWriter object for merging\nwriter = PdfWriter()\n\n# Add all pages from the reader to the writer\nfor page in reader.pages:\n    writer.add_page(page)\n\n# Add a blank page\nwriter.add_blank_page(width=72, height=72)\n\n# Write the output PDF to a file\noutput_pdf_path = \"merged_output.pdf\"\nwith open(output_pdf_path, \"wb\") as fp:\n    writer.write(fp)\n\nprint(f\"Successfully created {output_pdf_path} with {len(writer.pages)} pages.\")\n\n# Clean up dummy file\nos.remove(dummy_pdf_path)\nos.remove(output_pdf_path)","lang":"python","description":"This quickstart demonstrates basic PDF operations (reading, extracting text, merging, and adding pages) using `pypdf`, the actively maintained successor to `PyPDF2`. It creates a dummy PDF if one doesn't exist for the example to run."},"warnings":[{"fix":"Uninstall `pypdf2` (`pip uninstall pypdf2`), then install `pypdf` (`pip install pypdf`). Update import statements and class names in your code.","message":"The `PyPDF2` project has been officially renamed to `pypdf` and is now actively maintained under that name. The `pypdf2` PyPI package (version 3.0.1) is deprecated and acts as a wrapper around an older version of `pypdf` (specifically, `pypdf` 3.0.1). Users are strongly advised to migrate to `pypdf` for ongoing support, new features, and critical security updates.","severity":"breaking","affected_versions":"All `pypdf2` versions"},{"fix":"Update imports to `from pypdf import PdfReader, PdfWriter` and rename class instances (e.g., `PdfFileReader` to `PdfReader`, `PdfFileWriter` to `PdfWriter`).","message":"Prior to `PyPDF2` version 3.0.0 (which became the `pypdf` 3.0.1 wrapper), the API involved `import PyPDF2` and class names like `PyPDF2.PdfFileReader` and `PyPDF2.PdfFileWriter`. The modern `pypdf` API (and the `pypdf2 >= 3.0.0` wrapper) uses `from pypdf import PdfReader, PdfWriter` and respective class names.","severity":"breaking","affected_versions":"PyPDF2 < 3.0.0"},{"fix":"Migrate to the latest `pypdf` release (`pip install --upgrade pypdf`) to benefit from crucial security fixes and performance enhancements.","message":"Older versions of `PyPDF2` (pre-3.0.0, i.e., those that are not the `pypdf` 3.0.1 wrapper) contain known performance issues and critical security vulnerabilities, including infinite loop exploits and denial-of-service vectors. Even `pypdf2` 3.0.1, while wrapping `pypdf` 3.0.1, is significantly behind the latest `pypdf` (currently 6.x.x), which has received numerous security patches and performance improvements. Continuing to use `pypdf2` is not recommended for security-sensitive applications.","severity":"gotcha","affected_versions":"All `PyPDF2` versions; `pypdf2` 3.0.1 (compared to latest `pypdf`)"},{"fix":"Always use `pip install pypdf` and refer to the official `pypdf` documentation to ensure you are using the correct and most up-to-date library.","message":"The history of Python PDF libraries is complex, with several forks and renames including `pyPdf`, `PyPDF2`, `PyPDF3`, and `PyPDF4`. This can lead to significant confusion regarding which library is current and actively maintained. `pypdf` (the successor to `PyPDF2`) is the currently recommended and actively developed library.","severity":"gotcha","affected_versions":"All users of Python PDF libraries"},{"fix":"Review your code for `replace_contents` usage. Consult the `pypdf` documentation for alternative approaches or ensure you are using it only as intended by the library maintainers.","message":"The method `PageObject.replace_contents` was documented as potentially problematic and its usage on `PdfReader` objects was specifically advised against in `pypdf` 6.8.0. Incorrect usage can lead to unintended side effects or corrupted PDF files.","severity":"deprecated","affected_versions":"`pypdf` (and thus `pypdf2` wrapper) versions 6.8.0 and higher where `replace_contents` is used in a potentially problematic way."}],"env_vars":null,"search_vec":"'3.0.1':38,56 '6':74 'activ':58 'api':52 'capabl':19 'compat':47 'crop':23 'current':71 'deprec':2,42,94 'design':13 'develop':59 'document':92 'featur':61 'file':16,95 'final':35 'function':44 'happen':66 'intern':49 'librari':12,80 'like':20 'major':36 'manipul':17,96 'merg':22 'migrat':3 'new':60,83 'offer':18 'offici':41 'ongo':85 'packag':30 'page':27 'pdf':15,26,86,91 'process':87,93 'project':70 'pure':10 'pure-python':9 'pypdf':5,54,69 'pypdf2':1,6,29 'pypi':32 'python':11,90 'recommend':79 'secur':63 'split':21 'task':88 'transform':25 'updat':64 'use':50 'version':37,55,73 'wrapper':48 'x.x':75","created_at":"2026-04-14T03:40:02.141446+00:00","updated_at":"2026-04-16T19:38:21.832918+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/py-pdf/PyPDF2","docs":"https://pypdf2.readthedocs.io/en/latest/","changelog":"https://pypdf2.readthedocs.io/en/latest/meta/CHANGELOG.html","pypi":"https://pypi.org/project/pypdf2/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-08-30","next_check":"2026-07-30","install_tag":null}}