rcsb / py-rcsb-api

Python interface for RCSB.org API services
https://rcsbapi.readthedocs.io
MIT License
8 stars 0 forks source link

Switch from `requests` to `httpx` #33

Open dmyersturnbull opened 1 month ago

dmyersturnbull commented 1 month ago

requests is limited to HTTP/1.1. With httpx, you can build a client with httpx.Client(http1=False, http2=True), so that HTTP/2 is always used.

HTTP/3 support would be nice (it can be dramatically faster). RCSB doesn't support it yet, and we would need a separate package (aioquic), which is HTTP/3-only.

This line:

part_response = requests.post(headers={"Content-Type": "application/graphql"}, data=query, url=PDB_URL, timeout=10).json()

Can be:

with httpx.Client(http1=False, http2=True) as client:
    response = client.post(headers="Content-Type": "application/graphql"}, data=query, url=self.endpoint, timeout=self.timeout_sec)
    response.raise_for_status()
    data = response.json()

I'm also proposing replacing PDB_URL with an attribute self.endpoint and 10 with self.timeout_sec.