Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/python-api-v1-0-0-feedback.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Python API v1.0.0 Feedback
about: Feedback for the new Python Client API
about: Feedback for the new Python API
title: "[API v1.0.0 Feedback] description of feedback"
labels: python api feedback
assignees: ACscooter
Expand Down
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Add get_stats API to get observations given a StatisticalVariable and place dcids.

Expand All @@ -25,7 +25,7 @@ Bugs fixed in new release

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Handle and ignore NaN in API argument.

Expand All @@ -41,7 +41,7 @@ Bugs fixed in new release

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Use six package for urllib.

Expand All @@ -53,7 +53,7 @@ New features added to the Python Client API

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Support python 2.7.

Expand All @@ -65,7 +65,7 @@ New features added to the Python Client API

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Add a new API for getting related places.

Expand All @@ -79,7 +79,7 @@ New features added to the Python Client API

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Remove the dependency on Pandas and Numpy in package dependency.
- Replace requests with urllib.
Expand All @@ -93,7 +93,7 @@ New features added to the Python Client API

**Release Status** - Current head of branch [`master`](https://github.com/datacommonsorg/api-python/tree/master)

New features added to the Python Client API
New features added to the Python API

- Remove the dependency on Pandas.

Expand All @@ -106,7 +106,7 @@ New features added to the Python Client API

**Release Status** - Current head of branch [`stable-1.x`](https://github.com/datacommonsorg/api-python/tree/stable-1.x)

New features added to the Python Client API
New features added to the Python API

- Added two new functions `get_pop_obs` and `get_place_obs`
- SPARQL query is now supported as a function `query` instead of a class.
Expand All @@ -123,7 +123,7 @@ Bugs fixed in new release

**Release Tag** - [v1.0.0](https://github.com/datacommonsorg/api-python/releases/tag/v1.0.0)

New release of the Python Client API.
New release of the Python API.

- New functions in the API built on top of the [Data Commons REST API](https://github.com/datacommonsorg/mixer).
- `get_property_labels`
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ Once the package is installed, import `datacommons`.

import datacommons as dc

You will also need to provision an API key by enabling the Data Commons API on
GCP. Once you have the API key, simply add the following line to your code.

dc.set_api_key('YOUR-API-KEY')

For more detail on getting started with the API, please visit
[Getting Started](http://docs.datacommons.org/api/).

Expand Down
6 changes: 3 additions & 3 deletions datacommons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# Data Commons SPARQL query support
from datacommons.query import query

# Data Commons Python Client API
# Data Commons Python API
from datacommons.core import get_property_labels, get_property_values, get_triples
from datacommons.places import get_places_in, get_related_places, get_stats
from datacommons.populations import get_populations, get_observations, get_pop_obs, get_place_obs

# Other utilities
from .utils import set_api_key
# Other utilities
from .utils import set_api_key
2 changes: 1 addition & 1 deletion datacommons/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API Core.
""" Data Commons Python API Core.

Provides primitive operations for working with collections of nodes. For a
collection of nodes identified by their dcids, this submodule implements the
Expand Down
2 changes: 1 addition & 1 deletion datacommons/examples/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API examples.
""" Data Commons Python API examples.

Basic demo for get_property_labels, get_property_values, and get_triples.
"""
Expand Down
2 changes: 1 addition & 1 deletion datacommons/examples/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API examples.
""" Data Commons Python API examples.

Basic demo for get_places_in
"""
Expand Down
2 changes: 1 addition & 1 deletion datacommons/examples/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API examples.
""" Data Commons Python API examples.

Basic demo for get_populations and get_observations.
"""
Expand Down
2 changes: 1 addition & 1 deletion datacommons/examples/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API examples.
""" Data Commons Python API examples.

Example on how to use the Client API SPARQL query wrapper.
"""
Expand Down
2 changes: 1 addition & 1 deletion datacommons/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API Places Module.
""" Data Commons Python API Places Module.

Provides convenience functions for working with Places in the Data Commons
Graph. This submodule implements the ability to access :obj:`Place`'s
Expand Down
2 changes: 1 addition & 1 deletion datacommons/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API Populations Module.
""" Data Commons Python API Populations Module.

Provides convenience functions for accessing :obj:`StatisticalPopulation`'s and
:obj:`Observation`'s in the Data Commons Graph. Implements the
Expand Down
11 changes: 3 additions & 8 deletions datacommons/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
""" Data Commons Python Client API Query Module.
""" Data Commons Python API Query Module.

Implements functions for sending graph queries to the Data Commons Graph.
"""
Expand All @@ -20,7 +20,7 @@
from __future__ import division
from __future__ import print_function

from datacommons.utils import _API_ROOT, _API_ENDPOINTS, _ENV_VAR_API_KEY
from datacommons.utils import _API_ROOT, _API_ENDPOINTS

import json
import os
Expand Down Expand Up @@ -85,14 +85,9 @@ def query(query_string, select=None):
... print(r)
{"?name": "Maryland", "?dcid": "geoId/24"}
"""
# Get the API Key and perform the POST request.
if not os.environ.get(_ENV_VAR_API_KEY, None):
raise ValueError(
'Request error: Must set an API key before using the API!')
req_url = _API_ROOT + _API_ENDPOINTS['query']

req_url = _API_ROOT + _API_ENDPOINTS['query']
headers = {
'x-api-key': os.environ[_ENV_VAR_API_KEY],
'Content-Type': 'application/json'
}
req = six.moves.urllib.request.Request(
Expand Down
41 changes: 2 additions & 39 deletions datacommons/test/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# 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.
""" Data Commons Python Client API unit tests.
""" Data Commons Python API unit tests.

Unit tests for core methods in the Data Commons Python Client API.
Unit tests for core methods in the Data Commons Python API.
"""

from __future__ import absolute_import
Expand Down Expand Up @@ -43,11 +43,6 @@ def read(self):
req = args[0]
data = json.loads(req.data)

# If the API key does not match, then return 403 Forbidden
api_key = req.get_header('X-api-key')
if api_key != 'TEST-API-KEY':
return urllib.error.HTTPError

# Mock responses for urlopen requests to get_property_labels.
if req.full_url == utils._API_ROOT + utils._API_ENDPOINTS['get_property_labels']:
if data['dcids'] == ['geoId/0649670']:
Expand Down Expand Up @@ -323,9 +318,6 @@ def test_single_dcid(self, urlopen_mock):
""" Calling get_property_labels with a single dcid returns a valid
result.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Test for outgoing property labels
out_props = dc.get_property_labels(['geoId/0649670'])
self.assertDictEqual(out_props,
Expand All @@ -340,9 +332,6 @@ def test_multiple_dcids(self, urlopen_mock):
""" Calling get_property_labels returns valid results with multiple
dcids.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

dcids = ['State', 'County', 'City']
expected_in = ["typeOf"]
expected_out = ["name", "provenance", "subClassOf", "typeOf", "url"]
Expand All @@ -368,9 +357,6 @@ def test_bad_dcids(self, urlopen_mock):
""" Calling get_property_labels with dcids that do not exist returns empty
results.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Test for outgoing property labels
out_props = dc.get_property_labels(['dc/MadDcid'])
self.assertDictEqual(out_props, {'dc/MadDcid': []})
Expand All @@ -382,8 +368,6 @@ def test_bad_dcids(self, urlopen_mock):
@mock.patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
def test_no_dcids(self, urlopen_mock):
""" Calling get_property_labels with no dcids returns empty results. """
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Test for outgoing property labels
out_props = dc.get_property_labels([])
Expand All @@ -404,9 +388,6 @@ def test_multiple_dcids(self, urlopen_mock):
""" Calling get_property_values with multiple dcids returns valid
results.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

dcids = ['geoId/06085', 'geoId/24031']

# Get the containedInPlace Towns for Santa Clara and Montgomery County.
Expand Down Expand Up @@ -444,9 +425,6 @@ def test_bad_dcids(self, urlopen_mock):
""" Calling get_property_values with dcids that do not exist returns empty
results.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

bad_dcids_1 = ['geoId/06085', 'dc/MadDcid']
bad_dcids_2 = ['dc/MadDcid', 'dc/MadderDcid']

Expand All @@ -470,9 +448,6 @@ def test_bad_property(self, urlopen_mock):
""" Calling get_property_values with a property that does not exist returns
empty results.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Get propery values for a property that does not exist.
prop_vals = dc.get_property_values(
['geoId/06085', 'geoId/24031'], 'madProperty')
Expand All @@ -484,9 +459,6 @@ def test_bad_property(self, urlopen_mock):
@mock.patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
def test_no_dcids(self, urlopen_mock):
""" Calling get_property_values with no dcids returns empty results. """
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Get property values with an empty list of dcids.
prop_vals = dc.get_property_values([], 'containedInPlace')
self.assertDictEqual(prop_vals, {})
Expand All @@ -497,9 +469,6 @@ class TestGetTriples(unittest.TestCase):
@mock.patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
def test_multiple_dcids(self, urlopen_mock):
""" Calling get_triples with proper dcids returns valid results. """
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Call get_triples
triples = dc.get_triples(['geoId/06085', 'geoId/24031'])
self.assertDictEqual(triples, {
Expand All @@ -520,9 +489,6 @@ def test_bad_dcids(self, urlopen_mock):
""" Calling get_triples with dcids that do not exist returns empty
results.
"""
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Call get_triples where one dcid does not exist
triples_1 = dc.get_triples(['geoId/06085', 'dc/MadDcid'])
self.assertDictEqual(triples_1, {
Expand All @@ -544,9 +510,6 @@ def test_bad_dcids(self, urlopen_mock):
@mock.patch('six.moves.urllib.request.urlopen', side_effect=request_mock)
def test_no_dcids(self, urlopen_mock):
""" Calling get_triples with no dcids returns empty results. """
# Set the API key
dc.set_api_key('TEST-API-KEY')

# Call get_triples with no dcids
triples_1 = dc.get_triples([])
self.assertDictEqual(triples_1, {})
Expand Down
Loading