GlobusApp: Simplified Globus Python Scripting

October 16, 2024

Globus is happy to announce the release of GlobusApp, a simple and configurable authentication management tool now available in the Globus Python SDK.

Until now, performing even simple service interactions with the Globus Python SDK required developers to understand how to orchestrate the multi-step OAuth2 flows needed to retrieve and manage tokens that authenticate and authorize those requests. GlobusApp provides two new classes—UserApp and ClientApp—that can automatically handle necessary Auth interactions for many applications, minimizing the amount of knowledge needed to start working with Globus services in Python.

A GlobusApp can manage tokens for multiple service clients (in a single thread). Service logins are automatically bundled to minimize the number of manual steps a user has to perform.

Code Demo

The following two scripts both prompt a user to log in, then print out a collection’s root directory (assuming they actually have access to that collection). In the first example, the traditional OAuth 2 flow is manually implemented by the script:

Listing Files without GlobusApp
Figure 1 - Listing Files without GlobusApp

In the second example a GlobusApp (in this case a UserApp) handles it automatically:

Listing Files with GlobusApp
Figure 2 - Listing Files With GlobusApp

In addition to needing significantly more lines of code to perform the same operation, the pre-GlobusApp script in figure 1 does not store tokens—requiring a new user authentication flow every time it runs. By contrast, the shorter script in figure 2 automatically stores tokens on the user’s file system, re-using them on each subsequent script run until they expire.

Configurability

UserApp and ClientApp provide reasonable default settings, allowing them to be instantiated succinctly (minimally a client ID is required for UserApp; a client ID and client secret for ClientApp) and function as most developers expect.

However, some applications require alternate behavior. Developers may, for instance, prefer to store access tokens in a distributed database or in memory in their application rather than in a JSON file on disk. For those instances, developers can configure their GlobusApp by supplying a GlobusAppConfig data object. The list of configurable facets, extensions, and prebuilt alternates are documented at GlobusApp Configuration.

Getting Started

If you’d like to get started with GlobusApp (or simply understand it better), you can learn more in the GlobusApp documentation—a helpful guide to understanding and selecting the type of GlobusApp which fits your use case.