File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -354,6 +354,18 @@ Works()["W2023271753"].ngrams()
354
354
```
355
355
356
356
357
+ ### Serialize
358
+
359
+ All results from PyAlex can be serialized. For example, save the results to a JSON file:
360
+
361
+ ``` python
362
+ with open (Path(" works.json" ), " w" ) as f:
363
+ json.dump(Works().get(), f)
364
+
365
+ with open (Path(" works.json" )) as f:
366
+ works = [Work(w) for w in json.load(f)]
367
+ ```
368
+
357
369
## Code snippets
358
370
359
371
A list of awesome use cases of the OpenAlex dataset.
Original file line number Diff line number Diff line change @@ -244,6 +244,17 @@ def test_serializable(tmpdir):
244
244
assert "W4238809453" in json .load (f )["id" ]
245
245
246
246
247
+ def test_serializable_list (tmpdir ):
248
+ with open (Path (tmpdir , "test.json" ), "w" ) as f :
249
+ json .dump (Works ().get (), f )
250
+
251
+ with open (Path (tmpdir , "test.json" )) as f :
252
+ works = [Work (w ) for w in json .load (f )]
253
+
254
+ assert len (works ) == 25
255
+ assert all (isinstance (w , Work ) for w in works )
256
+
257
+
247
258
def test_ngrams_without_metadata ():
248
259
r = Works ()["W2023271753" ].ngrams (return_meta = False )
249
260
You can’t perform that action at this time.
0 commit comments