Stay organized with collections Save and categorize content based on your preferences.
A library is a script project whose functions can be reused in other scripts.
Warning: A script that uses a library doesn't run as quickly as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in add-ons. Gain access to a libraryTo include a library in your project you must have at least view-level access to it. If you aren't the author of the library that you want to include, contact the author and request access.
You need the script ID of the library you want to include. When you have access to the library, you can find the script ID on the Project Settings settings page.
Add a library to your script projectTest
then you can call a method of that library as follows: Test.libraryMethod()
. If you use an identifier name that matches the name of an already existing service, such as MailApp
, or a previously added library, then the library you have added most recently overrides the existing service or library.Use your included library as you would use a default service. For example, if Test
is the identifier for your library, type Test
immediately followed by a period to see the list of methods in the library.
The reference documentation for an included library can be opened by following these steps:
At the left of the script editor, next to the library name, click More more_vert > Open in a new tab.
Remove a libraryAt the left of the script editor, next to the library name, click More more_vert > Remove > Remove library.
If a library is deleted by the author you still need to remove it from your list of included libraries. Update a libraryYou can change the version of the library or update its identifier.
To use and share your script project as a library, follow the below steps.
Here are some guidelines to follow when writing a library:
myPrivateMethod_()
.var
, and properties explicitly set on the global object. For example, Object.defineProperty()
with enumerable
set to false
creates a symbol you can use in your library, but this symbol isn't accessible by your users.If you want your library users to make use of the script editor autocomplete and the automatically generated documentation, you must have JSDoc-style documentation for all your functions. Here's an example:
/**
* Raises a number to the given power, and returns the result.
*
* @param {number} base the number we're raising to a power
* @param {number} exp the exponent we're raising the base to
* @return {number} the result of the exponential calculation
*/
function power(base, exp) { ... }
There are two types of resources when you are working with libraries: shared and not-shared. A shared resource means that both the library and the including script have a built-in access to the same instance of the resource. The following diagram illustrates a shared resource using the example of User Properties:
A not-shared resource means that both library and the including script have built-in access only to their instance of the resource. However, a library can provide access to its not-shared resources by having explicit functions that operate on them. Here is an example of a function that you would include in your library to expose its Script Properties:
function getLibraryProperty(key) {
const scriptProperties = PropertiesService.getScriptProperties();
return scriptProperties.getProperty(key);
}
The following diagram illustrates a not-shared resource using the example of Script Properties:
This table lists the shared and not-shared resources for your reference:
Test a libraryTo test your library, use the head deployment. Anyone who has editor-level access to the script can use the head deployment.
You still need at least one version of the library saved. Debug a libraryWhen you use the debugger in a project that includes a library you can step into a function of the included library. The code shows up in the debugger in view-only mode and at the right version.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-04 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-04 UTC."],[[["Libraries in Apps Script enable code reuse across different scripts but can impact execution speed, especially in UI-heavy applications or add-ons."],["To use a library, you need its Script ID and at least view-level access, then add it to your project specifying the version and identifier."],["Libraries are accessed like built-in services; use the identifier followed by a period to view available methods."],["When creating a library, use meaningful names, consider visibility of methods (using underscores for private ones), and provide JSDoc documentation for user-facing functions."],["Libraries and scripts share certain resources like User Properties, while others, like Script Properties, are not shared and require explicit functions for access."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4