Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To query Data Commons from Python, install datacommons-client, create a DataCommonsClient, and choose the endpoint that fits your task: observation for statistics, node for graph details, or resolve for finding Data Commons IDs (DCIDs). V2 requests to the base Data Commons service require an API key; custom instances can be configured with a hostname or API URL.

What the Data Commons Python client does

The Data Commons Python API is a client library for programmatically accessing nodes in the Data Commons knowledge graph and using its statistics in data-analysis workflows. The V2 client implements the REST V2 APIs and adds Python convenience methods. The package is named datacommons-client; its import namespace is datacommons_client. See the official Python client guide.

The client supports three broad kinds of work:

  • Retrieve statistical observations for variables, dates, and entities.
  • Explore graph nodes, their properties, and their relations.
  • Resolve human-readable entity names to DCIDs and search for variables.

How do I install the Data Commons Python client?

The official guide recommends using python3 and pip3 in an isolated virtual environment. Activate the environment before installing the package. The guide does not state a current minimum Python version or package release number, so check the package’s current installation details if your environment has version constraints.

  1. Create and activate a virtual environment using your platform’s usual Python workflow.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    #1 Best Overall
    Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
    • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
    • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
    • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
    • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
    • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  2. Install the core client:

    pip install datacommons-client
  3. If you want observation results as Pandas DataFrames, install the optional extra:

    pip install "datacommons-client[Pandas]"

Import the package namespace, not the distribution name used by pip:

from datacommons_client.client import DataCommonsClient

Does the Data Commons Python API require an API key?

Yes, for the base Data Commons service with V2. The Python client guide and the API overview say that base-service access requires authentication and authorization with an API key. The client propagates the key with its requests. The API overview says keys are managed through a self-service portal and that users must enable the APIs they need. The Python guide describes a limited-quota trial key for single requests and recommends requesting an official key for more rigorous use; it gives no numeric quota.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

The client documentation says custom Data Commons instances do not require an API key. For a public custom instance, configure its DNS hostname. For a private or local instance, configure its full API URL, including the protocol and /core/api/v2/ path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I connect to the base service or a custom instance?

Construct a client with the connection details appropriate to your target. These examples show the documented options:

from datacommons_client.client import DataCommonsClient

# Base Data Commons service: provide an API key
client = DataCommonsClient(api_key="YOUR_API_KEY")

# Public custom instance: provide its DNS hostname
custom_client = DataCommonsClient(dc_instance="datacommons.one.org")

# Local or private custom instance: provide the full V2 API URL
local_client = DataCommonsClient(url="http://localhost:8080/core/api/v2/")
Target Client setting Authentication
Base Data Commons service api_key="YOUR_API_KEY" API key required for V2.
Public custom instance dc_instance="datacommons.one.org" (replace with its hostname) The Python client guide says no key is required.
Private or local custom instance url="http://localhost:8080/core/api/v2/" (replace with the instance’s full API URL) The Python client guide says no key is required.

For a private or local deployment, use the API URL exposed by that instance rather than assuming the example hostname, port, or protocol matches your setup. The client’s configuration depends on the instance’s endpoint being reachable from your Python environment.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Which endpoint should I use?

The V2 client groups common operations into three endpoint classes. Choose by the question you need to answer, rather than by the kind of output you hope to get.

Endpoint Use it for Typical starting point
observation Statistical observations and checking which data exists for entities and variables. Time series or comparisons across places and dates.
node Graph information, including properties, edges, and neighboring nodes. Inspecting a known node or following its relations.
resolve Finding DCIDs for entities and searching for variables. Starting with a place name or variable name rather than an ID.

Many operations accept relation expressions, and convenience methods cover common tasks. Name resolution can return multiple candidates: the official guide’s example for “Georgia” returns several DCIDs. Treat the result as a candidate list to disambiguate, not a guarantee that a place name maps to one unique entity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use observation for data values

Start with observation when you need statistical values associated with variables, entities, and dates. It is also the natural place to check whether the data you want is available before building a comparison or time-series workflow. If you need table-shaped results, the optional Pandas support provides observation results as pandas.DataFrame through a client-level method.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Use node to inspect the graph

Choose node when your question concerns a graph entity’s properties, edges, or neighboring nodes rather than a statistical observation. This can help you inspect relationships after you have a DCID or another suitable node reference.

Use resolve when you have names, not DCIDs

Choose resolve when a query begins with a human-readable place or variable name. Because a name can yield multiple entity candidates, applications that need a particular jurisdiction or entity type should inspect and disambiguate the returned DCIDs before using them downstream.

How should I handle client responses?

Responses are Python response objects by default. The documentation describes .to_dict() and .to_json() as formatting methods. Their compact default, exclude_none=True, removes null values and empty lists. Set it to False when preserving the original structure matters, for example when downstream code needs to distinguish an absent or empty field from one omitted during formatting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

V2 response structures are nested and include additional properties and metadata. Code that extracts values should inspect the returned structure rather than assuming that a statistic is presented as a simple flat value. The optional Pandas workflow is an alternative for observation data when a DataFrame better fits your analysis; it does not change the need to choose the correct endpoint or understand the returned fields.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What changed between Data Commons Python API V1 and V2?

The official V1-to-V2 migration guide documents changes that affect authentication, client construction, endpoint use, and result interpretation. It said V1 was planned for deprecation in early 2026, but the reviewed documentation does not establish whether that retirement has since taken effect. Check the current migration guide and service notices before treating V1 as unavailable.

Area V1 V2 Migration implication
Base-service authentication No API key required. API key required. Obtain and configure a key for base-service requests.
Client construction Sessions were managed through the package object. Create a datacommons_client client object. Update initialization and the code that owns the client session.
Custom instances Not supported. Supported. Choose the hostname or full API URL for the target instance.
Endpoint organization V1 methods used a different interface. Organized around node, observation, and resolve, with variations handled through parameters. Map each old call to the V2 endpoint and its parameters.
Entity resolution and pagination DCID resolution was not provided as described for V2; large results required pagination. DCID resolution is added, and pagination is optional rather than required for large query results. Review resolution workflows and any code that assumes it must page through every large result.
Response structure Simpler and mostly value-focused. Nested, with additional properties and metadata. Revise parsing and tests that expect flat or value-only results.
Observation facets Methods described in the guide selected a “relevant” facet, often the most recent. All available facets are returned by default unless filtered. Specify or process facets deliberately so results match the intended analysis.
Pandas support Separate package. Optional extra in the same installable package. Install datacommons-client[Pandas] if the DataFrame workflow is needed.

Migration checklist

  • Change base-service authentication to use an API key.
  • Replace package-managed sessions with an initialized V2 client object.
  • Map existing calls to node, observation, or resolve and confirm their parameters.
  • Update response parsing for nested structures and metadata.
  • Review pagination logic and make explicit choices about observation facets.
  • Install the Pandas extra if the project uses DataFrames.

Where can I learn more or use Data Commons another way?

The official documentation covers the REST API, Python client, and Pandas API. Data Commons also offers Colab tutorials, Google Sheets integration, web components for embedded visualizations, and CSV download tools. These serve different workflows: scripted analysis, spreadsheets, website embeds, or downloaded data.

For teaching and early data-science practice, the introductory data-science materials provide adaptable Python notebook assignments using real-world Data Commons data. Listed examples cover feature engineering, classification and model evaluation, regression, and clustering. The page describes online educational resources for teachers, professors, instructors, teaching assistants, and early practitioners.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.