Skip to main content

PyPDB

A Python 3 toolkit for performing searches with the RCSB Protein Data Bank (PDB). This can be used to perform advanced searches for PDB IDs matching various criteria, as well as to look up information associated with specific PDB IDs. This tool allows standard operations that can be perfomed from within the PDB website (BLAST, PFAM lookup, etc.) to be performed from within Python scripts.

If you use this module for any published work, please consider citing the accompanying paper

  Gilpin, W. "PyPDB: A Python API for the Protein Data Bank."
  Bioinformatics, Oxford Journals, 2016.

Installation

Install using pip:

$ pip install pypdb

Or using conda, from conda-forge:

$ conda install -c conda-forge pypdb

To install the development version, which contains the latest features and fixes, install directly from GitHub using

$ pip install git+https://github.com/williamgilpin/pypdb

To install from a local checkout,

$ pip install .

For development and test dependencies,

$ pip install -e ".[dev]"

Test the installation, and check that the code successfully connects to the PDB, navigate to the root directory and run

$ python -m pytest

This code has been designed and tested for Python 3.

Usage

Search the PDB for entries matching a term, and get back a list of PDB IDs:

from pypdb import Query

found_pdbs = Query("ribosome").search()
print(found_pdbs[:5])

The query_type argument searches a specific field instead of the full text. A few of the most common:

# By source organism
Query("Dictyostelium", query_type="OrganismQuery").search()

# By Enzyme Classification number (partial numbers match the whole subtree)
Query("2.3.2.5", query_type="ec_number").search()

# By UniProt accession
Query("P68871", query_type="uniprot").search()

# By experimental method
Query("SOLID-STATE NMR", query_type="ExpTypeQuery").search()

# By ligand, either as a chemical component ID or a SMILES string
Query("NAG", query_type="chemical").search()
Query("Clc1nc(Br)nc2nc[nH]c12", query_type="chemical").search()

Other query types include PubmedIdQuery, TreeEntityQuery (NCBI TaxID), AdvancedAuthorQuery, pfam, sequence, seqmotif, and structure. See help(Query) for the full list.

For queries combining several conditions with AND/OR logic, negation, ranges, or comparisons, see search/EXAMPLES.md.

PDB Data Fetch

Look up the information associated with a single PDB ID:

from pypdb import get_info

info = get_info("4HHB")
print(info["struct"]["title"])     # THE CRYSTAL STRUCTURE OF HUMAN DEOXYHAEMOGLOBIN...
print(info["exptl"][0]["method"])  # X-RAY DIFFRACTION

List the polymer chains in an entry. Chain IDs live on an entry's polymer entities in the current RCSB API, so they are not part of get_info:

from pypdb import get_chains, get_chain_ids

for entity in get_chains("4HHB"):
    print(entity["chains"], entity["description"])
# ['A', 'C'] Hemoglobin subunit alpha
# ['B', 'D'] Hemoglobin subunit beta

print(get_chain_ids("4HHB"))  # ['A', 'B', 'C', 'D']

Fetch the ligands bound to an entry, or the description of a chemical component:

from pypdb import get_ligands, describe_chemical

ligands = get_ligands("4HHB")["ligandInfo"]["ligand"]
print([ligand["@chemicalID"] for ligand in ligands])  # ['HEM', 'PO4']

print(describe_chemical("NAG")["chem_comp"]["name"])

Download a structure file:

from pypdb import get_pdb_file

cif = get_pdb_file("4lza", filetype="cif", compression=True)

Ligand coordinates

Ligand coordinates can be downloaded in either of the two forms the RCSB website offers, both in Kekule form. Ideal coordinates come from the Chemical Component Dictionary and are independent of any structure; instance coordinates are the ligand as modelled inside one particular entry:

from pypdb import get_ideal_ligand_file, get_ligand_instances, get_ligand_instance_file

# Idealized coordinates for a chemical component (SDF only)
sdf = get_ideal_ligand_file("ATP")

# Coordinates of each copy as modelled in an entry (SDF or MOL2)
for instance in get_ligand_instances("4HHB"):
    coords = get_ligand_instance_file("4HHB",
                                      instance["auth_asym_id"],
                                      instance["auth_seq_id"],
                                      filetype="mol2")

get_ligand_instances reports the chain and residue number of every ligand copy in an entry, which is what identifies a specific instance to download.

Integrated PubMed, UniProt, and structural interface data can be fetched as well. For fetching many properties across many entries at once, see data/EXAMPLES.md.

Counting and paginating results

Searches return every matching entry by default, which can be slow for broad queries. To retrieve just a tally or the highest-scoring hits:

from pypdb import count_results, get_top_results

print(count_results("ribosome"))            # 9560
print(get_top_results("crispr", max_results=5))

Searches can also be restricted to a page of results, scored with a particular strategy, or extended to include computed structure models (such as AlphaFold predictions) via RequestOptions. See search/EXAMPLES.md.

More worked examples of every function live in demos/demos.ipynb.

Releasing a new version

The git tag is the only place the version is written. To publish a release to PyPI, tag and push:

git tag v2.9 && git push origin v2.9

That's the whole process — there is no version file to edit. setuptools-scm derives the package version from the tag at build time and writes it into pypdb/_version.py, which is generated rather than checked in (it is listed in .gitignore).

Pushing a v* tag runs the tests, builds the distributions, and uploads them to PyPI. This uses PyPI Trusted Publishing, so no API token is stored in the repository — it requires a one-time publisher registration on PyPI pointing at the python-publish.yml workflow and the pypi environment.

Between releases, pypdb.__version__ reports a development version derived from the most recent tag (e.g. 2.9.dev1+g1a2b3c4).

Issues and Feature Requests

If you run into an issue, or if you find a workaround for an existing issue, please post your question or code as a GitHub issue.

If posting a feature request, please check that your request is possible using the current GUI on current RCSB website. If so, please perform your search, and then click the link that says JSON in the upper right hand corner of the Advanced Search box. Please post that JSON code with your feature request.

Metadata

Release files for pypdb 2.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypdb 2.11
File Size Uploaded
pypdb-2.11.tar.gz 75.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypdb 2.11
File Interpreter ABI Platform
pypdb-2.11-py3-none-any.whl Python 3 none any Details

Total release size: 141.4 kB

Release files / pypdb-2.11.tar.gz

Download URL pypdb-2.11.tar.gz
Size 75.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f9404470c9b7c58b53cb599fe39755c4be360c59e462fb44ffd1cb6667e53b1
BLAKE2b-256 checksum
How to use checksums
25c5ada9592e1391c2535a2ac1ba07511a95e2535f240eab0efe97aca0275518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release files / pypdb-2.11-py3-none-any.whl

Download URL pypdb-2.11-py3-none-any.whl
Size 66.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33af97dda1079855bc180213e674a2bfaa4537edcd0167f9d73c26d35ea45d5c
BLAKE2b-256 checksum
How to use checksums
7a7cea86e869a196e1375dfcf634e9694dc3d2c75489554863b2e4815c59b6a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.11 This release

2 release files

2.10

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0

3 release files

1.310

2 release files

1.300

1 release file

1.200

2 release files

1.103

1 release file

1.102

1 release file

1.101

1 release file

1.31

3 release files

1.2

1 release file

1.1

1 release file

1.0

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page