Authentication
You can use earthaccess
to search for datasets and data without needing to log in.
However, to access (download or stream) NASA Earth science data, whether from one of the NASA
Distributed Active Archive Centers (DAACs) on-premises archive or from NASA Earthdata Cloud, you need
an Earthdata Login account. You can register for a free Earthdata Login (EDL) account here.
Once you have an Earthdata Login account, you may use the earthaccess.login
method to manage Earthdata Login credentials and, when you are working with cloud-hosted data, cloud credentials.
earthaccess.login
offers three methods of logging in (or authenticating) using EDL:
- an interactive login method, where you enter EDL username and password manually
- an automatic login method using EDL credentials stored in a
.netrc
file - an automatic login method using EDL credentials stored in environment variables.
By default, earthaccess.login()
will look for a .netrc
or environment variables first. If neither of these are found, it will prompt you to enter your username and password. The three methods are described in detail below.
earthaccess.login
can also be used to login to different endpoints and get S3 credentials.
Login Interactively
If you have not created a .netrc
file or EARTHDATA_USERNAME
and EARTHDATA_PASSWORD
environment variables, you can use the following approach to login.
>>> import earthaccess
>>> auth = earthaccess.login()
Enter your Earthdata Login username: your_username
Enter your Earthdata password:
You don't need to assign the result of earthaccess.login()
to a variable but doing so enables access to session information. These are discussed in Accessing Session Information.
Setting earthaccess.login(strategy=interactive)
will force a manual login.
Login using a .netrc
Do not use this strategy on untrusted machines or with shared accounts
earthaccess
does not currently support encrypted .netrc
files. This strategy of writing credentials in plain text to disk
should not be used on untrusted machines or shared user accounts.
Creating a .netrc
file
Using earthaccess.login
to create a .netrc
file
You can use earthaccess.login
to create a .netrc
for you.
.netrc
(or _netrc
) file will be created automatically.
Manually creating a .netrc
file for Earthdata Login Credentials
Type the following on your command line, replacing <username>
and <password>
with your
Earthdata Login credentials.
Type the following on your command line, replacing <username>
and <password>
with your
Earthdata Login credentials.
In a CMD
session, create a %HOME%
environment variable. The following line
creates %HOME%
from the path in %USERPROFILE%
, which looks something like
C:\Users\"username"
.
_netrc
file in %HOME%
.
Login using environment variables
Alternatively, Earthdata Login credentials can be created as environment variables EARTHDATA_USERNAME
and EARTHDATA_PASSWORD
.
If you want to set the environment variables for the current shell session, type the following on the command line.
If you want to set these environmental variables permanently, add these two lines to the appropriate configuration files for your operating system.If you want to set the environment variables for the current shell session, type the following on the command line.
If you usebash
and would like to set these environmental variables permanently, add these two lines to your ~/.profile
file:
For other shells, use the recommended method to persistently set these environment variables for whichever shell you use.
To set the environment variables for the current CMD
session, type the following:
Accessing different endpoints
Earthdata User Acceptance Testing (UAT) endpoint
If your EDL account is authorized to access the User Acceptance Testing (UAT) environment,
you can set earthaccess to work with its EDL and CMR endpoints
by setting the system
argument at login, as follows:
Using earthaccess
to get S3 credentials
earthaccess.login
is a very convenient way to manage and provide Earthdata Login credentials. earthaccess.login
can also be used to obtain S3 credentials to access NASA Earthdata Cloud. If you use earthaccess
to access data in the cloud, you do not have to use this option, earthaccess
handles this. However, if you are using other packages, such as h5coro
, earthaccess
can save a lot of time.
import earthaccess
import xarray as xr
import h5coro
auth = earthaccess.login()
s3_credentials = auth.get_s3_credentials(daac="NSIDC")
s3url_atl23 = 'nsidc-cumulus-prod-protected/ATLAS/ATL23/001/2023/03/' \
'01/ATL23_20230401000000_10761801_001_01.h5'
ds = xr.open_dataset(s3url_atl23, engine='h5coro',
group='/mid_latitude/beam_1',
credentials=s3_credentials)