A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/apps-script/managing_libraries below:

Libraries | Apps Script | Google for Developers

Skip to main content Libraries

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 library

To 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 project
  1. At the left of the Apps Script editor, next to "Libraries," click Add a library add.
  2. In the "Script ID" field, paste in the script ID of the library.
  3. Click Look up. If you encounter an error, make sure that you have at least view-level access to the project that you're trying to include.
  4. Click the Version dropdown and select the version of the library to use.
  5. Check to see if the default "Identifier" name is the one that you want to use with this library. This is the name that your script uses to refer to the library. For example, if you set it to Test 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.
  6. Click Add.
Use a 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 library

At 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 library

You can change the version of the library or update its identifier.

  1. At the left of the editor, under "Libraries," click the name of the library.
  2. Make your changes and click Save.

To use and share your script project as a library, follow the below steps.

  1. Create a versioned deployment of your script.
  2. Share at least view-level access with all potential users of the library.
  3. Give those users the script ID, which can be found on the Project settings settings page.
Best practices

Here are some guidelines to follow when writing a library:

  1. Choose a meaningful name for your project since it's used as the default identifier when your library is included by others.
  2. If you want one or more methods of your script to not be visible (nor usable) to your library users, you can end the name of the method with an underscore. For example, myPrivateMethod_().
  3. Only enumerable global properties are visible to library users. This includes function declarations, variables created outside a function with 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.
  4. 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) { ... }
    
Resource scoping

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 library

To 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 library

When 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