Skip to main content

Python package interface for RCSB.org API services

Project description

PyPi Release Build Status Documentation Status

rcsb-api

Python interface for RCSB PDB API services at RCSB.org.

This package requires Python 3.7 or later.

Installation

Get it from PyPI:

pip install rcsb-api

Or, download from GitHub

Getting Started

Full documentation available at readthedocs.

The RCSB PDB Data API supports requests using GraphQL, a language for API queries. This package simplifies generating queries in GraphQL syntax.

In GraphQL, you must begin your query at specific fields. These "input_types" are fields like entry, polymer_entity, and polymer_entity_instance . You request data through the "return_data_list" argument. Available data can be explored with the GraphiQL editor's documentation explorer.

Examples

This is a simple query requesting the experimental method of a structure with PDB ID 4HHB (Hemoglobin).

The query must be executed using the .exec() method, which will return the JSON response as well as store the response as an attribute of the Query object. From the object, you can access the Data API response, get an interactive editor link, or access the arguments used to create the query.

from rcsbapi.data import Query
query = Query(
    input_type="entry",
    input_ids={"entry_id": "4HHB"},
    return_data_list=["exptl.method"]
)
print(query.exec())

Data is returned in JSON format

{"data": {"entry": {"exptl": [{"method": "X-RAY DIFFRACTION"}]}}}

Here is a more complex query. Note that periods can be used to further specify requested data in return_data_list. Also note multiple return data items and ids can be requested in one query.

from rcsbapi.data import Query
query = Query(
    input_type="polymer_entities",
    input_ids=["2CPK_1", "3WHM_1", "2D5Z_1"],
    return_data_list=[
        "polymer_entities.rcsb_id",
        "rcsb_entity_source_organism.ncbi_taxonomy_id",
        "rcsb_entity_source_organism.ncbi_scientific_name",
        "cluster_id",
        "identity"
    ]
)
print(query.exec())

Jupyter Notebooks

A notebook briefly summarizing the readthedocs is available in notebooks/quickstart.ipynb or online through Google Colab Open In Colab

Another notebook using both Search and Data API packages for a COVID-19 related example is available in notebooks/search_data_workflow.ipynb or online through Google Colab Open In Colab.


Learn about more features and troubleshooting at the readthedocs page and walk through some examples using the Juptyer notebooks!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rcsb_api-0.3.0.tar.gz (280.0 kB view hashes)

Uploaded Source

Built Distribution

rcsb_api-0.3.0-py2.py3-none-any.whl (293.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page