Skip to main content

Project logo

Published Docs Tests

Mozilla Data Collective Python Client Library

The official Python SDK for accessing and contributing to the Mozilla Data Collective platform.

[!WARNING] Our platform is evolving rapidly. Expect breaking changes while the Python SDK is on 0.X.X versions. Please ensure you are always on the latest version available.

Installation

pip install datacollective

Quick Start

IMPORTANT NOTE: Before trying to access any dataset, make sure you have thoroughly read and agreed to the specific dataset's conditions & licensing terms.

  1. Get your API key from the Mozilla Data Collective dashboard

  2. Set the API key in your environment variable:

Option A: Run this command in your terminal (replace your-api-key-here with your actual API key):

export MDC_API_KEY=your-api-key-here

Option B: Create a .env file in your project directory and add this line:

MDC_API_KEY=your-api-key-here
  1. Get your dataset ID from the last section of the dataset URL at the MDC website.

[!TIP] You can find the dataset-id by looking at the URL of the dataset's page on MDC platform. The ID is the unique string of characters located at the very end of the URL, after the /datasets/ path. For example, for URL https://mozilladatacollective.com/datasets/cminc35no007no707hql26lzk dataset id will be cminc35no007no707hql26lzk.

  1. Save a dataset locally:
from datacollective import download_dataset

dataset_path = download_dataset("your-dataset-id")

[!NOTE] download_dataset was previously called save_dataset_to_disk. The old name still works for backward compatibility, but it is deprecated and new code should use download_dataset.

[!TIP] Automatic Resume: If a download is interrupted (e.g., due to a network error or it gets stopped it manually), the next time you try download the same dataset at the same folder location, we will automatically resume from where the download left off!

[!TIP] Set enable_logging=True to emit detailed SDK logs to the console and a local log file at ~/.mozdata/datacollective.log with timestamped entries, a per-session id, and retention of 5 backup files at 10 MB each.

  1. Get information & metadata about a dataset:
from datacollective import get_dataset_details

details = get_dataset_details("your-dataset-id")
  1. Load the dataset into a pandas DataFrame (Alpha version: Only certain MDC datasets are supported right now):
from datacollective import load_dataset

dataset = load_dataset("your-dataset-id")
  1. Or load it as a HuggingFace Dataset object (requires the optional hf extra: pip install / uv add "datacollective[hf]"):
from datacollective import load_dataset

dataset = load_dataset("your-dataset-id", return_format="hf")

Returns a Dataset, or a DatasetDict keyed by split name for datasets with multiple splits. See our docs for more details, including how to lazily decode audio with the Audio() feature.

Programmatic submissions and uploads

You can create dataset submissions and upload files with resumable uploads into the MDC platform programmatically using our Python SDK:

from datacollective import DatasetSubmission, License, Task, create_submission_with_upload

submission = DatasetSubmission(
    name="Dataset Name",
    longDescription="A detailed description of the dataset.",
    shortDescription="A brief description of the dataset.",
    locale="en-US",
    task=Task.ASR,
    format="TSV",
    licenseAbbreviation=License.CC_BY_4_0,
    other="This text should provide a detailed description of the dataset, "
          "including its contents, structure, and any relevant information "
          "that would help users understand what the dataset is about "
          "and how it can be used.",
    restrictions="Any restrictions you want to impose on the dataset",
    forbiddenUsage="Use cases that are not allowed with this dataset",
    additionalConditions="Any additional conditions for using the dataset",
    pointOfContactFullName="Jane Doe",
    pointOfContactEmail="jane@example.com",
    fundedByFullName="Funder Name",
    fundedByEmail="funder@example.com",
    legalContactFullName="Legal Name",
    legalContactEmail="legal@example.com",
    createdByFullName="Creator Name",
    createdByEmail="creator@example.com",
    intendedUsage="Describe the intended usage of the dataset, including "
                  "potential applications and use cases.",
    ethicalReviewProcess="Describe the ethical review process that was "
                         "followed for this dataset, including any approvals "
                         "or considerations related to data collection and usage.",
    exclusivityOptOut=False,  # True = This dataset is non-exclusive to Mozilla Data Collective, 
                              # False = Dataset is exclusively hosted in Mozilla Data Collective
    agreeToSubmit=True,  # True = You confirm that you have the right to submit this dataset and 
                         # that all information provided in the datasheet is accurate. 
                         # Required to be True to complete the submission process
)

response = create_submission_with_upload(
    file_path="/path/to/dataset.tar.gz",
    submission=submission
)

print(response)

For predefined licenses, pass licenseAbbreviation=License.<VALUE> and leave licenseUrl and license unset. For custom licenses, pass a custom string to license and optionally include licenseUrl and licenseAbbreviation.

[!TIP] To upload a new .tar.gz version to an already approved dataset, call upload_dataset_file(file_path=..., submission_id=...) directly. Find the submission under Profile → Uploads, open the approved dataset, and copy the value after /profile/submissions/ in the URL. Note that this value is the submission ID, which is different from the public dataset ID.

For more details, visit our docs

License

This project is released under MPL (Mozilla Public License) 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datacollective-0.5.4.tar.gz (42.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datacollective-0.5.4-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file datacollective-0.5.4.tar.gz.

File metadata

  • Download URL: datacollective-0.5.4.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for datacollective-0.5.4.tar.gz
Algorithm Hash digest
SHA256 12be17920a1d587a004c9340adf449ec6342ee34a8257f7fd551887d24496399
MD5 3b36b5b147d4ecd96a27e63621c131ce
BLAKE2b-256 cd24897b558fb640fa1ad96ff259c284957df514ed935deff7781333b27ec507

See more details on using hashes here.

File details

Details for the file datacollective-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: datacollective-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for datacollective-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bfb2539732d33cf8591f2460790285196837f057d9af2a06426e058e1468751c
MD5 b2ad4be9038f9c91b195eecf8da0e4ec
BLAKE2b-256 ba0998b3e5f912dd8beb3b1b62db1b6341e84177f269a1f8c304f6b69ccef191

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.7

2 files

0.5.6

2 files

0.5.5

2 files

This release

0.5.4 This release

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.34

2 files

0.0.33

2 files

0.0.32

2 files

0.0.27

2 files

0.0.23

2 files

0.0.16

2 files

0.0.11

2 files

0.0.8

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page