problems about python library

78 views
Skip to first unread message

闫帅

unread,
Nov 6, 2015, 9:39:07 AM11/6/15
to Dataverse Users Community
I want to use python library of dataverse to do some matters.       I wrote the simple script to test the API after installed the python libary in my centos system. but it occured  the error as follows:
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from dataverse import Connection
ImportError: No module named dataverse

the script as follows: 

from dataverse import Connection

host = 'apitest.dataverse.org'                  # All clients >4.0 are supported
token = '4d0634d3-74d5-4770-8088-1971847ac75e'  # Generated at /account/apitoken
connection = Connection(host, token)


I had no idea with the error, hope some guys can help me .

Philip Durbin

unread,
Nov 6, 2015, 4:50:09 PM11/6/15
to dataverse...@googlegroups.com
As a starting point, can you try something like this?

$ python mytest.py
Found a dataset...
OSF Test doi:10.7910/DVN/14KSUG
Try get_dataset_by_doi method...
Using get_dataset_by_doi method, found dataset: OSF Test
Found a dataset...
Geospatial Test doi:10.7910/DVN/IPI8AQ
Try get_dataset_by_doi method...
Using get_dataset_by_doi method, found dataset: Geospatial Test
(dataverse-client-python)murphy:dataverse-client-python pdurbin$ cat mytest.py
from dataverse import Connection
from secrets import API_TOKEN

connection = Connection("dataverse.harvard.edu", API_TOKEN)
dataverse = connection.get_dataverse('pdurbin')
for dataset in dataverse.get_datasets():
    print "Found a dataset..."
    print dataset.title, dataset.doi
    doi = dataset.doi
    print "Try get_dataset_by_doi method..."
    dataset_by_doi = dataverse.get_dataset_by_doi(doi)
    print "Using get_dataset_by_doi method, found dataset:", dataset_by_doi.title
(dataverse-client-python)murphy:dataverse-client-python pdurbin$
(dataverse-client-python)murphy:dataverse-client-python pdurbin$ cat secrets.py
API_TOKEN = "FIXME"

I'm sorry this is so brief. Gotta run. Have a good weekend and please me know if this helps!

Phil

--
You received this message because you are subscribed to the Google Groups "Dataverse Users Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-commu...@googlegroups.com.
To post to this group, send email to dataverse...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-community/ca61dbe9-d349-4018-bd45-3fb61f11c56a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

闫帅

unread,
Nov 10, 2015, 3:14:17 AM11/10/15
to dataverse...@googlegroups.com
Hi Phil,
 
Thanks for your reply. The script is OK. But you API_TOKEN and dataverse info seems wrong,which throw the error as follows: 
内嵌图片 1 

the script worked with myself information. And I just wonder how we can to search other's dataverse without them API_TOKEN within python client? And thanks again for your warmhearted and earnest attitude.


yan

--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/X309brf-xRU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-commu...@googlegroups.com.

To post to this group, send email to dataverse...@googlegroups.com.

Philip Durbin

unread,
Nov 10, 2015, 8:41:57 AM11/10/15
to dataverse...@googlegroups.com
Yeah, I didn't want to give you my API token. :)

The Python client was initially developed back in the DVN 3.x days when we only had a SWORD API and another API that has since been discontinued. The Dataverse SWORD API only works with datasets you have permission to. If you want to search *other* people's datasets and files, you should use the Search API: http://guides.dataverse.org/en/4.2.1/api/search.html

Unfortunately, the Python client does not yet support the Search API: https://github.com/IQSS/dataverse-client-python/issues/21

I hope this helps!

Phil


For more options, visit https://groups.google.com/d/optout.

Romain MOUGIN

unread,
Nov 12, 2015, 4:52:50 AM11/12/15
to Dataverse Users Community, philip...@harvard.edu
If it can help, I had to make some python scripts in order to navigate through dataverses and datasets in the dataverse root. I use the python API for Dataverses and datasets manipulation (creating/editing, only "yours", of course), and for datasets and dataverse's research, for example, I use the "native" way. For my scripts, I can navigate through all the dataverse root, find the datasets and dataverse I want, and get the metadatas of this objects thanks to the native API. Maybe that's what you wanted ? Dunno the performances for search, depends of the Native API responsiveness, but at least, you can do it in Python :)

The Native API doc (very easy to use with python, can give you some code examples if needed ): http://guides.dataverse.org/en/4.2.1/api/native-api.html

闫帅

unread,
Nov 15, 2015, 8:14:53 AM11/15/15
to dataverse...@googlegroups.com


Yeah,thanks for your attention. Your suggestion is helpful. It would be better, if you can give me some code examples.

yan

2015-11-12 17:52 GMT+08:00 Romain MOUGIN <romain...@sciencespo.fr>:
If it can help, I had to make some python scripts in order to navigate through dataverses and datasets in the dataverse root. I use the python API for Dataverses and datasets manipulation (creating/editing, only "yours", of course), and for datasets and dataverse's research, for example, I use the "native" way. For my scripts, I can navigate through all the dataverse root, find the datasets and dataverse I want, and get the metadatas of this objects thanks to the native API. Maybe that's what you wanted ? Dunno the performances for search, depends of the Native API responsiveness, but at least, you can do it in Python :)

The Native API doc (very easy to use with python, can give you some code examples if needed ): http://guides.dataverse.org/en/4.2.1/api/native-api.html

--------------------------------------------------------------------------
Tous les courriers électroniques émis depuis la messagerie de Sciences Po doivent respecter les conditions d'usage.
Pour les consulter rendez-vous sur :

--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/X309brf-xRU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-commu...@googlegroups.com.
To post to this group, send email to dataverse...@googlegroups.com.

闫帅

unread,
Nov 15, 2015, 8:21:15 AM11/15/15
to Dataverse Users Community, philip...@harvard.edu
yeah,it is. thanks for your attention.

在 2015年11月10日星期二 UTC+8下午9:41:57,Philip Durbin写道:
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/X309brf-xRU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Dataverse Users Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-community+unsub...@googlegroups.com.

To post to this group, send email to dataverse...@googlegroups.com.

Romain MOUGIN

unread,
Nov 16, 2015, 5:38:26 AM11/16/15
to Dataverse Users Community, philip...@harvard.edu
Here is a code example using the native api to retrieve informations about a specific dataset with the datasetId, then duplicate it in your own dataverse :

from dataverse import Connection, Dataverse, Dataset
import requests, json

 # Connect to the HOST (dataverse url) with your personal TOKEN
connection = Connection(HOST, TOKEN)

# Considering this dataset Id exists
datasetId = 111
       
# Prepare the get url to use with the native api
url = "http://"+HOST+"/api/datasets/"+datasetId+"?key="+TOKEN
# add it to the request
r = requests.get(url)

# Get the json returned by the request
datas = json.loads(r.text)
# For example, here, you get the name of the dataset thanks to the datas of your GET request
datasetName = datas['data']['latestVersion']['metadataBlocks']['citation']['fields'][0]['value']

# Your dataverse alias
dataverseAlias = DATAVERSEALIAS
# Get your Dataverse object with the python API
dataverse = connection.get_dataverse(dataverseAlias)

# I couldn't make a dataset directly with metadatas, so I first make an "empty" dataset
duplicatedDataset = dataverse.create_dataset(title=duplicatedDatasetTitle,
                                                 description=duplicatedDatasetDescription,
                                                 creator=duplicatedDatasetCreator
                                                 )
# Use the metadatas retrieved earlier and update your new dataset with this datas
duplicatedDataset.update_metadata(datasetSrcMetadata['data']['latestVersion'])
# You now have on your personal a copy of a dataset that is not yours :)

Vyacheslav Tikhonov

unread,
Nov 16, 2015, 2:01:30 PM11/16/15
to Dataverse Users Community
Well, if it will help you we already have Python based data processing engine to get all datasets from Dataverse and store in mongodb. There is also possibility to combine/analyze/visualize datasets online.
You can get the idea and download some source code from https://github.com/4tikhonov/clioinfra.js

I hope it will help as there are really a lot of examples how to use Native API.

Regards,
Slava


On Sunday, November 15, 2015 at 2:14:53 PM UTC+1, 闫帅 wrote:


Yeah,thanks for your attention. Your suggestion is helpful. It would be better, if you can give me some code examples.

yan
2015-11-12 17:52 GMT+08:00 Romain MOUGIN <romain...@sciencespo.fr>:
If it can help, I had to make some python scripts in order to navigate through dataverses and datasets in the dataverse root. I use the python API for Dataverses and datasets manipulation (creating/editing, only "yours", of course), and for datasets and dataverse's research, for example, I use the "native" way. For my scripts, I can navigate through all the dataverse root, find the datasets and dataverse I want, and get the metadatas of this objects thanks to the native API. Maybe that's what you wanted ? Dunno the performances for search, depends of the Native API responsiveness, but at least, you can do it in Python :)

The Native API doc (very easy to use with python, can give you some code examples if needed ): http://guides.dataverse.org/en/4.2.1/api/native-api.html

--------------------------------------------------------------------------
Tous les courriers électroniques émis depuis la messagerie de Sciences Po doivent respecter les conditions d'usage.
Pour les consulter rendez-vous sur :

--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/X309brf-xRU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-community+unsub...@googlegroups.com.

To post to this group, send email to dataverse...@googlegroups.com.

闫帅

unread,
Nov 23, 2015, 10:31:02 AM11/23/15
to dataverse...@googlegroups.com
hi,
  
Sorry to reply so latter. thanks very much.

yan

--------------------------------------------------------------------------
Tous les courriers électroniques émis depuis la messagerie de Sciences Po doivent respecter les conditions d'usage.
Pour les consulter rendez-vous sur :

--
You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/X309brf-xRU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-commu...@googlegroups.com.

To post to this group, send email to dataverse...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages