python-cmr
raw JSON → 0.13.0 verified Fri May 01 auth: no python
Python wrapper to the NASA Common Metadata Repository (CMR) API. Version 0.13.0, supports Python 3.8-3.12. Active development, irregular releases.
pip install python-cmr Common errors
error ImportError: No module named cmr ↓
cause Virtual environment not activated or package not installed.
fix
Run
pip install python-cmr and ensure your Python environment is correct. error AttributeError: 'CMR' object has no attribute 'search_collections' ↓
cause Deprecated method removed in newer version.
fix
Use
cmr.collection_query().get() instead. error cmr.errors.CMRException: HTTP 401 Unauthorized ↓
cause Missing or invalid Earthdata Login credentials for restricted data.
fix
Set environment variables
CMR_USERNAME and CMR_PASSWORD, or pass token to CMR(). error ValueError: Invalid environment 'prod'. Must be one of: 'prod', 'uat', 'ops'. ↓
cause Case-sensitive environment name.
fix
Use lowercase: 'prod', 'uat', or 'ops'.
Warnings
gotcha Calls to `.get()` return raw JSON, not Python objects. Access fields via dictionary keys. ↓
fix Use `collections[0]['meta']['concept-id']` instead of `collection.concept_id`.
breaking CMR API v3 was deprecated in python-cmr 0.10.0; v3 endpoints may be removed in future releases. ↓
fix Upgrade to latest version; if you rely on v3 specific features, pin to <0.10.0.
gotcha Environment parameter in CMR() defaults to 'prod'. Use 'uat' for testing. Mixing up environments causes empty results or auth errors. ↓
fix Explicitly set `CMR(environment='uat')` for test environment.
deprecated The `CMR().search_collections()` method is deprecated in favor of `CMR().collection_query().get()`. ↓
fix Replace `cmr.search_collections(...)` with `cmr.collection_query().filter(...).get()`.
Imports
- CMR
from cmr import CMR - GranuleQuery wrong
from cmr import Granulecorrectfrom cmr import GranuleQuery - CollectionQuery
from cmr import CollectionQuery
Quickstart
from cmr import CMR
# Initialize CMR client with optional auth
cmr = CMR(environment='prod')
# Search for collections
collections = cmr.collection_query().keyword('temperature').get()
print(collections[:2])
# Search for granules
granules = cmr.granule_query().short_name('MOD11A1').get()
print(granules[:2])