Submind YouTube summaries
Thumbnail for Data Skills Tutorial: How to Create and Use a NEON API Token in R and Python

Data Skills Tutorial: How to Create and Use a NEON API Token in R and Python

Watch on YouTube

Video summary

Starting June 2026, NEON has implemented a new requirement mandating that users possess an API token to download data programmatically from their portal. This measure is designed to mitigate bot scraping activities and enhance overall user support systems. To obtain this necessary credential, individuals must first establish a NEON account by visiting neonscience.org and either logging in or signing up using options like Google or CI login. Once registered, users can access the API token section within their account settings after verifying their email address; clicking the generate button creates a unique token with an expiration date that is automatically copied to the clipboard for immediate use. For R users, securing this token involves storing it as a persistent environment variable in a file named .Renviron, which can be easily created or edited using the usethis package via the console command `usethis::edit_r_environ()`. By adding a line formatted as `neon_token = [your-token-here]` to this file and saving it with Ctrl+S, users ensure their code has secure access without hardcoding sensitive information. It is crucial to restart the R session after making these changes so that the system recognizes the new variable, which can then be retrieved using `Sys.getenv("neon_token")` for use in any NEON utilities function or data download script. Python developers follow a similar security protocol but typically utilize an `.env` file located at the root of their project directory to store environment variables like the neon token. Using the python-dotenv package, scripts can load these settings by importing `load_env` from the dotenv module and specifying the path if necessary; this process confirms successful loading before allowing access via `os.getenv("neon_token")`. This approach keeps credentials separate from the main codebase while enabling seamless integration into Python notebooks or scripts that interact with the NEON API. Finally, it is essential to maintain security best practices by excluding sensitive files such as .Renviron and .env from version control systems like Git through entries in a `.gitignore` file, preventing accidental exposure of tokens during repository sharing. The video concludes by directing viewers to additional resources on the NEON tutorial page for both short and comprehensive guides on managing these tokens across different environments. By following these steps, researchers can efficiently set up their accounts, generate secure API credentials, and configure them correctly in R or Python to continue accessing valuable ecological data without interruption.
Read the full video transcript
In this video, we will show how to create a NEON API token and set it up as an environment variable so you can use it in both R and Python for downloading NEON data. As of June 2026, NEON is requiring an API token in order to download any NEON data. This requirement is intended to reduce bot scraping and to improve user support. To generate a token, you will first need to create a NEON user account if you don't already have one. To do this, navigate to the NEON website, neonscience.org, and click on sign in in the upper right corner. This will bring up a pop-up with either a login or a sign up option. I'll go ahead and show how to sign up for the first time. There are options also to sign up with Google or CI login. Once you've signed in, you can click on the my account in the upper right-hand corner. You can authorize, which will load a page that populates your name automatically. You can fill in your organization, title, country, and Orchid ID. And then you can also select products of interest, sites of interest, and so forth. To create a token, first you need to send a verification email. Once you have verified your email address, you may need to sign out and sign back in. Back in your my account page, if you scroll down again, you can now see the API token section and a little box that says get API token. Click on this to generate a token, and here you can see a token has been generated, which you can copy. It shows you the expiration date and the state. If you ever need to delete or create a new token, you can either disable it or delete it in this actions panel. Now that the token has been saved to the clipboard, we can set it as an environment variable so your code can access it securely. In R, we typically store persistent environment variables in a file called .Renviron. An easy way to open or create this file is with the usethis package. In your R console, run usethis edit .Renviron and click enter, which will pop up the .Renviron file. Within this file, you can add a new line with the format neon_token = and then paste the token that has been copied to the clipboard. Press Ctrl S to save, and then you can close this file. You'll need to restart R for these changes to take effect, which you can do by clicking session restart R. And then once R has restarted, you can read in the token to a variable called token using Sys.getenv neon_token. And then confirm that the token has been read in by printing it. This token can then be used in any neonUtilities function or whenever you run scripts that interact with the NEON API in order to download NEON data. Next, let's set up the token to use in Python. In Python, environment variables are usually set at the operating system level or stored in a file called .env or .env for your project. A common approach is to use a .env file along with the python-dotenv package. First, create a file in your project directory at the root level called .env. Here, we've created it at the root level of the NEON data skills repository. And then in that file, we've typed neon_token = and then copied the token from the clipboard. In your Python script or notebook, you can load the environment variables using the python.env package as follows. First, import os. Then, from .env import load_env. Then, if you're located in the directory where you have the .env stuff file saved, you can use load_env. And note that if you are in a different directory, you can specify the path to the .env file. If it's successfully located, you should see the output true. You can then read in your token using os.getenv neon_token. And then, ensure that it's been read in properly by printing it out. You can use this token in your NEON utilities functions or in any scripts that interact with the NEON API. In summary, starting in June 2026, NEON logins are required to download NEON data from the portal, and API tokens are required to download NEON data programmatically. In this video, we've covered how to set up a new NEON user account and create a NEON API token in neonscience.org. We also showed how to configure the API token for use in both R and Python using a .R environ file for R and a .env file for Python. If you are working in a Git repository, you will need to exclude these file types by adding them to your Git ignore file to ensure the tokens are secure. To follow along with self-paced online tutorials, check out the NEON tutorial page shown here and linked in the video notes. We have two tutorials that cover setting up API tokens. A short version, which covers what was shown in this video, called Set Up a NEON API Token, and a longer version covering a few more options for using tokens in R and Python called using an API token when accessing neon data with neon utilities. Please check these out along with any other neon tutorials of interest and subscribe to the neon science YouTube channel.