mpcontribs-client 5.6.0__py3-none-any.whl → 5.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,6 +59,8 @@ from pint.converters import ScaleConverter
59
59
  from pint.errors import DimensionalityError
60
60
  from tempfile import gettempdir
61
61
  from plotly.express._chart_types import line as line_chart
62
+ from cachetools import cached, LRUCache
63
+ from cachetools.keys import hashkey
62
64
 
63
65
  RETRIES = 3
64
66
  MAX_WORKERS = 3
@@ -680,7 +682,9 @@ def _load(protocol, host, headers_json, project, version):
680
682
  projects = sorted(d["name"] for d in resp["data"])
681
683
  projects_json = ujson.dumps(projects)
682
684
  # expand regex-based query parameters for `data` columns
683
- return _expand_params(protocol, host, version, projects_json)
685
+ spec = _expand_params(protocol, host, version, projects_json, apikey=headers.get("x-api-key"))
686
+ spec.http_client.session.headers.update(headers)
687
+ return spec
684
688
 
685
689
 
686
690
  @functools.lru_cache(maxsize=1)
@@ -714,15 +718,22 @@ def _raw_specs(protocol, host, version):
714
718
  return spec_dict
715
719
 
716
720
 
717
- @functools.lru_cache(maxsize=100)
718
- def _expand_params(protocol, host, version, projects_json):
721
+ @cached(
722
+ cache=LRUCache(maxsize=100),
723
+ key=lambda protocol, host, version, projects_json, **kwargs: hashkey(
724
+ protocol, host, version, projects_json
725
+ )
726
+ )
727
+ def _expand_params(protocol, host, version, projects_json, apikey=None):
719
728
  columns = {"string": [], "number": []}
720
729
  projects = ujson.loads(projects_json)
721
- query = {"project__in": projects}
730
+ query = {"project__in": ",".join(projects)}
722
731
  query["_fields"] = ["columns"]
723
732
  url = f"{protocol}://{host}"
724
733
  http_client = RequestsClient()
725
734
  http_client.session.headers["Content-Type"] = "application/json"
735
+ if apikey:
736
+ http_client.session.headers["X-Api-Key"] = apikey
726
737
  resp = http_client.session.get(f"{url}/projects/", params=query).json()
727
738
 
728
739
  for proj in resp["data"]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mpcontribs-client
3
- Version: 5.6.0
3
+ Version: 5.6.2
4
4
  Summary: client library for MPContribs API
5
5
  Home-page: https://github.com/materialsproject/MPContribs/tree/master/mpcontribs-client
6
6
  Author: Patrick Huck
@@ -26,6 +26,7 @@ Requires-Dist: swagger-spec-validator
26
26
  Requires-Dist: tqdm
27
27
  Requires-Dist: ujson
28
28
  Requires-Dist: semantic-version
29
+ Requires-Dist: cachetools
29
30
  Provides-Extra: dev
30
31
  Requires-Dist: flake8 ; extra == 'dev'
31
32
  Requires-Dist: pytest ; extra == 'dev'
@@ -0,0 +1,6 @@
1
+ mpcontribs/client/__init__.py,sha256=MdKExIkvHsduzHVDcZBwhJa4CCqYP519AXaWgVDcFEk,92644
2
+ mpcontribs_client-5.6.2.dist-info/LICENSE,sha256=5tG0Niaqw2hnuyZZYkRXLSnfVrZA47COwduU_6caPLM,1074
3
+ mpcontribs_client-5.6.2.dist-info/METADATA,sha256=T_dTSbw569Xs7H7OUCwa6a2J2U91v7t2JKwpcQlUupA,2548
4
+ mpcontribs_client-5.6.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
+ mpcontribs_client-5.6.2.dist-info/top_level.txt,sha256=t8R5L_Dg9oDQMh2gyRFdZGnrzZsr7OjCBTrhTcmimC8,11
6
+ mpcontribs_client-5.6.2.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- mpcontribs/client/__init__.py,sha256=7foA5jnfIQjTnB2Yg0DCCJAg_eKtpeFHcKFD9tGGfvo,92233
2
- mpcontribs_client-5.6.0.dist-info/LICENSE,sha256=5tG0Niaqw2hnuyZZYkRXLSnfVrZA47COwduU_6caPLM,1074
3
- mpcontribs_client-5.6.0.dist-info/METADATA,sha256=6Bk3618fuYeWA8_ts5P-sxU130ZUqWTIk_lOZkWNsos,2522
4
- mpcontribs_client-5.6.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
5
- mpcontribs_client-5.6.0.dist-info/top_level.txt,sha256=t8R5L_Dg9oDQMh2gyRFdZGnrzZsr7OjCBTrhTcmimC8,11
6
- mpcontribs_client-5.6.0.dist-info/RECORD,,