-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add warning for outdated local datasets - Fix config migration in case of malformed ~/.data.world - Relax validation of file names in dataset API responses to allow slashes - Improve content in help(datadotworld) - Return newly created dataset URL - Version and README updates in preparation for PyPI release Github Issues: - #27 - #19 - #26 - #24
- Loading branch information
Showing
26 changed files
with
18,383 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,155 @@ | ||
""" | ||
data.world-py | ||
Copyright 2017 data.world, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the | ||
License. | ||
# data.world-py | ||
# Copyright 2017 data.world, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the | ||
# License. | ||
# | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# | ||
# This product includes software developed at | ||
# data.world, Inc.(http://data.world/). | ||
|
||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
implied. See the License for the specific language governing | ||
permissions and limitations under the License. | ||
""" | ||
A python library for working with data.world datasets | ||
This product includes software developed at | ||
data.world, Inc.(http://data.world/). | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from datadotworld.datadotworld import load_dataset, query, api_client | ||
import weakref | ||
|
||
from datadotworld.datadotworld import DataDotWorld | ||
|
||
__version__ = '1.0.0' | ||
|
||
# Convenience top-level functions | ||
|
||
__instances = weakref.WeakValueDictionary() | ||
|
||
|
||
def _get_instance(profile): | ||
instance = __instances.get(profile) | ||
if instance is None: | ||
instance = DataDotWorld(profile=profile) | ||
__instances[profile] = instance | ||
return instance | ||
|
||
|
||
def load_dataset(dataset_key, force_update=False, profile='default'): | ||
""" | ||
Load a dataset from the local filesystem, downloading it from data.world | ||
first, if necessary. | ||
This function returns an object of type `LocalDataset`. The object | ||
allows access to metedata via it's `describe()` method and to all the data | ||
via three properties `raw_data`, `tables` and `dataframes`, all of which | ||
are mappings (dict-like structures). | ||
Parameters | ||
---------- | ||
dataset_key : str | ||
Dataset identifier, in the form of owner/id or of a url | ||
force_update : bool | ||
Flag, indicating if a new copy of the dataset should be downloaded | ||
replacing any previously downloaded copy | ||
profile : str, optional | ||
Configuration profile (account) to use. | ||
Returns | ||
------- | ||
LocalDataset | ||
The object representing the dataset | ||
Raises | ||
------ | ||
RestApiError | ||
If a server error occurs | ||
Examples | ||
-------- | ||
>>> import datadotworld as dw | ||
>>> dataset = dw.load_dataset('jonloyens/an-intro-to-dataworld-dataset') | ||
>>> list(dataset.dataframes) | ||
['changelog', 'datadotworldbballstats', 'datadotworldbballteam'] | ||
""" | ||
return _get_instance(profile).load_dataset(dataset_key, | ||
force_update=force_update) | ||
|
||
|
||
def query(dataset_key, query, query_type='sql', profile='default'): | ||
"""Query an existing dataset | ||
Parameters | ||
---------- | ||
dataset_key : str | ||
Dataset identifier, in the form of owner/id or of a url | ||
query : str | ||
SQL or SPARQL query | ||
query_type : {'sql', 'sparql'}, optional | ||
The type of the query. Must be either 'sql' or 'sparql'. | ||
profile : str, optional | ||
Configuration profile (account) to use. | ||
Returns | ||
------- | ||
Results | ||
Object containing the results of the query | ||
Raises | ||
------ | ||
RuntimeError | ||
If a server error occurs | ||
Examples | ||
-------- | ||
>>> import datadotworld as dw | ||
>>> results = dw.query( | ||
... 'jonloyens/an-intro-to-dataworld-dataset', | ||
... 'SELECT * FROM `DataDotWorldBBallStats`, `DataDotWorldBBallTeam` ' | ||
... 'WHERE DataDotWorldBBallTeam.Name = DataDotWorldBBallStats.Name') | ||
>>> df = results.dataframe | ||
>>> df.shape | ||
(8, 6) | ||
""" | ||
return _get_instance(profile).query(dataset_key, query, | ||
query_type=query_type) | ||
|
||
|
||
def api_client(profile='default'): | ||
"""Return API client for access to data.world's REST API | ||
Parameters | ||
---------- | ||
profile : str, optional | ||
Configuration profile (account) to use. | ||
Returns | ||
------- | ||
RestApiClient | ||
REST API client object | ||
Examples | ||
-------- | ||
>>> import datadotworld as dw | ||
>>> client = dw.api_client() | ||
>>> client.get_dataset( | ||
... 'jonloyens/an-intro-to-dataworld-dataset').get('title') | ||
'An Intro to data.world Dataset' | ||
""" | ||
return _get_instance(profile).api_client | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
__version__ = '1.0.0-beta.5' | ||
doctest.testmod() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
""" | ||
data.world-py | ||
Copyright 2017 data.world, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the | ||
License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
implied. See the License for the specific language governing | ||
permissions and limitations under the License. | ||
This product includes software developed at | ||
data.world, Inc.(http://data.world/). | ||
""" | ||
# data.world-py | ||
# Copyright 2017 data.world, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the | ||
# License. | ||
# | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# | ||
# This product includes software developed at | ||
# data.world, Inc.(http://data.world/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.