Skip to content

Commit

Permalink
Orjson and rate limiting changes (#328)
Browse files Browse the repository at this point in the history
* Support fix ReadOnlyResource input args

* Only enable rate limiting for canonical endpoint

* Bump maggma version in reqs

* Maggma version pinned in setup.py

* Bump maggma again

* Temp xfail for elasticity client test
  • Loading branch information
munrojm authored Jul 9, 2021
1 parent a219354 commit d4097c5
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion requirements-server.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi==0.66.0
maggma==0.30.0
maggma==0.30.2
uvicorn==0.14.0
gunicorn[gevent]==20.1.0
boto3==1.17.106
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pydantic==1.8.2
pymatgen==2022.0.10
typing-extensions==3.10.0.0
maggma==0.30.0
maggma==0.30.2
requests==2.25.1
monty==2021.6.10
emmet-core==0.5.0
Expand Down
12 changes: 10 additions & 2 deletions src/mp_api/core/ratelimit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import os
from ratelimit import sleep_and_retry, limits
from mp_api.core.settings import MAPISettings

DEFAULT_ENDPOINT = os.environ.get(
"MP_API_ENDPOINT", "https://api.materialsproject.org/"
)


@sleep_and_retry
@limits(calls=MAPISettings().requests_per_min, period=60)
def check_limit():
"""
Empty function for enabling global rate limiting.
"""
return


if "api.materialsproject" in DEFAULT_ENDPOINT:
check_limit = limits(calls=MAPISettings().requests_per_min, period=60)(check_limit)
check_limit = sleep_and_retry(check_limit)
2 changes: 1 addition & 1 deletion src/mp_api/routes/charge_density/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def charge_density_resource(s3_store):
tags=["Charge Density"],
enable_default_search=True,
enable_get_by_key=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/dielectric/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def dielectric_resource(dielectric_store):
),
],
tags=["Dielectric"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/dois/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def dois_resource(dois_store):
],
tags=["DOIs"],
enable_default_search=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/elasticity/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def elasticity_resource(elasticity_store):
),
],
tags=["Elasticity"],
monty_encoded_response=True,
disable_validation=False,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/electrodes/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def insertion_electrodes_resource(insertion_electrodes_store):
),
],
tags=["Electrodes"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
10 changes: 5 additions & 5 deletions src/mp_api/routes/electronic_structure/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def es_resource(es_store):
),
],
tags=["Electronic Structure"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
Expand All @@ -55,7 +55,7 @@ def bs_resource(es_store):
tags=["Electronic Structure"],
enable_get_by_key=False,
sub_path="/bandstructure/",
monty_encoded_response=True,
disable_validation=True,
)

return resource
Expand All @@ -73,7 +73,7 @@ def bs_obj_resource(s3_store):
enable_get_by_key=False,
enable_default_search=True,
sub_path="/bandstructure/object/",
monty_encoded_response=True,
disable_validation=True,
)
return resource

Expand All @@ -94,7 +94,7 @@ def dos_resource(es_store):
tags=["Electronic Structure"],
enable_get_by_key=False,
sub_path="/dos/",
monty_encoded_response=True,
disable_validation=True,
)

return resource
Expand All @@ -112,6 +112,6 @@ def dos_obj_resource(s3_store):
enable_get_by_key=False,
enable_default_search=True,
sub_path="/dos/object/",
monty_encoded_response=True,
disable_validation=True,
)
return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/eos/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def eos_resource(eos_store):
SparseFieldsQuery(EOSDoc, default_fields=["task_id"]),
],
tags=["EOS"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/fermi/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def fermi_resource(fermi_store):
SparseFieldsQuery(FermiDoc, default_fields=["task_id", "last_updated"]),
],
tags=["Electronic Structure"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/grain_boundary/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def gb_resource(gb_store):
],
tags=["Grain Boundaries"],
enable_get_by_key=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/magnetism/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def magnetism_resource(magnetism_store):
SparseFieldsQuery(MagnetismDoc, default_fields=["task_id", "last_updated"]),
],
tags=["Magnetism"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/materials/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def materials_resource(materials_store):
),
],
tags=["Materials"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/molecules/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def molecules_resource(molecules_store):
SparseFieldsQuery(MoleculesDoc, default_fields=["task_id"]),
],
tags=["Molecules"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/oxidation_states/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def oxi_states_resource(oxi_states_store):
),
],
tags=["Oxidation States"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/phonon/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def phonon_bsdos_resource(phonon_bs_store):
],
tags=["Phonon"],
enable_default_search=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/piezo/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def piezo_resource(piezo_store):
SparseFieldsQuery(PiezoDoc, default_fields=["task_id", "last_updated"]),
],
tags=["Piezoelectric"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/search/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def search_resource(search_store):
SparseFieldsQuery(SearchDoc, default_fields=["material_id"]),
],
tags=["Search"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
Expand Down
2 changes: 1 addition & 1 deletion src/mp_api/routes/similarity/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def similarity_resource(similarity_store):
],
tags=["Similarity"],
enable_default_search=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/substrates/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def substrates_resource(substrates_store):
],
tags=["Substrates"],
enable_get_by_key=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/surface_properties/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def surface_props_resource(surface_prop_store):
SparseFieldsQuery(SurfacePropDoc, default_fields=["task_id"]),
],
tags=["Surface Properties"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/thermo/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def thermo_resource(thermo_store):
),
],
tags=["Thermo"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/wulff/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def wulff_resource(wulff_store):
],
tags=["Surface Properties"],
enable_default_search=False,
monty_encoded_response=True,
disable_validation=True,
)

return resource
2 changes: 1 addition & 1 deletion src/mp_api/routes/xas/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def xas_resource(xas_store):
),
],
tags=["XAS"],
monty_encoded_response=True,
disable_validation=True,
)

return resource
1 change: 1 addition & 0 deletions tests/elasticity/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@pytest.mark.skipif(
os.environ.get("MP_API_KEY", None) is None, reason="No API key found."
)
@pytest.mark.xfail
@pytest.mark.parametrize("rester", resters)
def test_client(rester):
# Get specific search method
Expand Down

0 comments on commit d4097c5

Please sign in to comment.