pyDataverse icon indicating copy to clipboard operation
pyDataverse copied to clipboard

Return a pyDataverse object from an API requests

Open Ajax23 opened this issue 6 years ago • 5 comments

When pulling a dataset, the response object contains the json of the dataset. Would it be attractive to instead return a Dataset object?

The Dataset class would simply contain getter and setter functions for all properties and the constructor only needs the json as an input. I assume this would improve clarity (one could create a print function to show the metadata maybe using pandas?).

Additionally, a Dataset object could be passed to other functions like create_dataset.

Ajax23 avatar Jun 14 '19 08:06 Ajax23

This is a good idea. I had at the beginning different return types implemented, but to offer full control to the user, i removed it.

Am trying to list up all return_types, that could be of interest

  • json (default)
  • dict
  • Dataset/Dataverse/Datafile object
  • requests object

skasberger avatar Jun 22 '19 18:06 skasberger

In the case of multiple returns, one could return a subDictionary containing all return types and the user can decide on the return desired.

return {'json':jsonObject, 'dict':dictObject, ...}
...
json = returnDict["json"]

Or some kind of return class.

json = returnClass.getJson()

Ajax23 avatar Jun 24 '19 09:06 Ajax23

In general, to keep the module as simple, tidy and modular as possible, I want to define each abstraction level in detail and give the users as much freedom as possible. A user should be able to decide, what it wants to do with the responses, and I should not limit their options I think. This said, from that point on, a lot of abstractions can be made, to offer functions for specific use-cases. Once the core works well, the next level of abstraction can be tackled.

To be more concrete: The first step is to develop get() and set() to create proper dicts as output. This will then be used to connect all kinds of i/o formats (to_json, from_json, to_xml, from_xml and so on). Once this is done, the passing of objects could also be an option (or just pass the Dataset.to_json() output as JSON string into the API call directly).

skasberger avatar Jun 26 '20 01:06 skasberger

Will be solved in #132.

skasberger avatar Feb 17 '21 22:02 skasberger

As discussed during the 2024-02-14 meeting of the pyDataverse working group, we are closing old milestones in favor of a new project board at https://github.com/orgs/gdcc/projects/1 and removing issues (like this one) from those old milestones. Please feel free to join the working group! You can find us at https://py.gdcc.io and https://dataverse.zulipchat.com/#narrow/stream/377090-python

pdurbin avatar Feb 14 '24 20:02 pdurbin