Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To share code or third-party libraries between Google Cloud Functions, make those libraries part of each function’s build dependency setup. Put the dependency declaration in the format required by that function’s runtime, test with the Functions Framework, and deploy from a source directory that contains the declaration (or a supported vendor directory). Google now calls the service Cloud Run functions; older documentation and URLs still say Cloud Functions.

A Python dependency workflow is not interchangeable with Node.js, Java, or Go. The reliable process is therefore: identify the runtime, follow its current dependency guide, make private packages reachable during the build, test locally, then deploy with a supported runtime version.

What “shared libraries” means in a function project

There are two different things developers often call a shared library:

  • A third-party package: an SDK, parser, database client, or other module downloaded during the build.
  • Your own reusable code: validation, authentication, logging, or domain logic used by several functions.

In both cases, the deployed function must be able to import the code from its build output. A package installed only on your workstation, or a sibling directory that is not included in the deployment source, is not a dependable dependency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a small project, each function can declare the same internal package and external modules. For a larger project, publish the shared package to an internal registry or include it through the runtime’s supported vendoring mechanism. Keep the public handler thin and put reusable logic in a package that can be unit-tested independently.

Choose the dependency method for your runtime

Google publishes a separate dependency workflow for each supported language. Use the page for the runtime you actually deploy; copying a Go command into a Python or Node.js project will not work.

Runtime Dependency declaration How deployment obtains code Private or restricted-network consideration Official reference
Go go.mod module file, or a vendor directory Modules listed in go.mod are incorporated during deployment; vendored files are included from the source tree. Vendor packages when a manager cannot reach a dependency. Google also recommends mirroring the Functions Framework in a private registry when avoiding public-internet fetches. Specify dependencies in Go
Python The dependency file and package-manager workflow documented for the selected Python runtime Follow the current Python build convention rather than a Node.js or Go layout. Use the package source and network controls supported by the Python guide. Specify dependencies in Python
Node.js The package manifest and install workflow documented for the selected Node.js runtime Use the Node.js convention for declaring and installing modules. Configure private registries and credentials according to the Node.js guide. Specify dependencies in Node.js
Java The build descriptor and dependency workflow documented for the selected Java runtime Use the Java build tool and layout required by that runtime. Use the repository and authentication approach supported by the Java guide. Specify dependencies in Java

The Python, Node.js, and Java pages are intentionally separate because their package managers, file names, and build behavior differ. Check those live pages for the current syntax before pinning a dependency or adding a build script.

Go: share modules with go.mod or vendor

Go has the clearest documented choice. A module file lists the libraries required by the function, and the Go deployment process incorporates those modules. A vendor directory places the dependency source beside your function and is useful when a dependency is unavailable through a manager or network access is restricted. The complete Go rules are in Google’s Go dependency guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Module-based project

Keep go.mod and go.sum at the deployment source root. Add the Functions Framework explicitly even though Google installs it on your behalf when creating a function; the explicit declaration documents what your source needs and makes local development reproducible.

module example.com/orders-function

go 1.22

require (
    # Add the current Functions Framework Go module version
    # and the versions of your application libraries here.
)

Use the current framework module and versions supported by the runtime you selected, then run the normal Go module tidy operation so checksums are recorded. Do not copy a version from an old tutorial without checking the live dependency page and runtime support table.

Reusable package and handler

Put shared logic in a package below the module path, and import it from every function that needs it. The following example shows the shape of a shared package and an HTTP handler; register the handler with the current Functions Framework Go launcher described in Google’s documentation.

// internal/orderid/orderid.go
package orderid

import "strings"

func Normalize(v string) string {
    return strings.ToUpper(strings.TrimSpace(v))
}

// function.go
package function

import (
    "fmt"
    "net/http"
    "example.com/orders-function/internal/orderid"
)

func Handle(w http.ResponseWriter, r *http.Request) {
    id := orderid.Normalize(r.URL.Query().Get("id"))
    if id == "" {
        http.Error(w, "id is required", http.StatusBadRequest)
        return
    }
    fmt.Fprintf(w, "order %s", id)
}

The package is shared because it is part of the same module delivered with the function. If several independently deployed functions consume it, publish it to a private module registry or vendor it into each deployment source rather than relying on a local relative path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Vendor-based project

Choose vendoring when the build cannot fetch a module, when policy requires all source to be present before deployment, or when you need a controlled snapshot of private dependencies. Fetch private modules into vendor before deployment and include that directory in the function source. Google’s guidance also recommends mirroring the Functions Framework to a private registry when you do not want deployment to retrieve it from the public internet.

Python, Node.js, and Java: follow the language page

Each of these runtimes has its own dependency convention and current package-manager requirements. Start with the corresponding official page:

Declare every library imported by the handler or shared package, commit the lock or checksum information expected by that ecosystem, and keep the declaration in the directory you deploy. Do not assume that a file named for one language will be detected by another. For private packages, configure the registry and credentials in the manner supported by that language’s build process; if the build environment cannot reach the registry, use the documented offline or vendoring option rather than hoping a workstation installation is copied.

Minimal Python handler shape

def hello_http(request):
    name = request.args.get("name", "world")
    return {"message": f"Hello, {name}!"}

Place the framework and application packages in the dependency file prescribed by the Python guide, using versions compatible with the selected runtime. The function code is portable; the dependency file and deployment command are runtime-specific.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Minimal Node.js handler shape

exports.helloHttp = (req, res) => {
  const name = req.query.name || 'world';
  res.status(200).send(`Hello, ${name}!`);
};

Declare the Functions Framework and any imported packages in the package manifest required by the Node.js guide. Keep the start script and entry-point setting aligned with that guide.

Java application shape

public class HelloHttp {
  public String hello(String name) {
    return "Hello, " + (name == null ? "world" : name) + "!";
  }
}

Use the Java build descriptor and Functions Framework setup documented for your chosen Java runtime. Java’s dependency resolution is not interchangeable with Go modules or a Node.js package manifest.

Local testing with the Functions Framework

The open-source Functions Framework libraries wrap a deployed function in a persistent HTTP application and can run it locally without rebuilding the deployment container. That makes dependency and handler failures visible before a cloud build.

  1. Install the Functions Framework using the package-manager instructions for your language.
  2. Start the local server with the entry point configured for your function.
  3. Send the same HTTP request shape your deployed trigger will receive.
  4. For event-driven code, send the CloudEvent signature covered by the local-development guide, not only a browser-style HTTP request.
  5. Change a shared package, restart the local process if required by your language, and rerun the request.

Use Google’s Local functions development guide for the current framework command, HTTP and CloudEvent signatures, and language-specific setup. Test missing parameters, malformed events, authentication failures, and the success path; a function that starts locally can still fail during dependency resolution in the cloud build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deployment workflow and runtime versions

  1. Select a supported runtime. Runtime versions and end-of-support dates change. Check the live runtime support table immediately before creating or upgrading a function.
  2. Prepare one clean source root. Include the handler, shared packages, dependency declaration, and any vendor directory required by your language. Remove workstation-only files and secrets.
  3. Resolve dependencies before deployment. Run the language’s package-manager or module command, commit the resulting lock/checksum files, and verify that private packages are reachable from the build environment.
  4. Run the Functions Framework locally. Exercise both normal and failure requests, including the event signature used in production.
  5. Deploy with Google’s current command and flags. The authoritative procedure, trigger syntax, region options, and runtime identifiers are in Deploy a Cloud Run function. Do not reuse a command written for an end-of-life runtime.
  6. Inspect the build and invocation. A successful upload is not proof that an import worked. Confirm the build completed, invoke the deployed endpoint or event trigger, and review logs for startup and dependency errors.

Private libraries and restricted network access

A private dependency adds a second failure point: the build must both know the package name and authenticate to its repository. Decide whether the runtime’s package manager can reach that repository during a managed build. If not, use the language’s supported vendor or offline method. Go explicitly documents fetching private dependencies into vendor; it also recommends a private mirror of the Functions Framework when public access is prohibited.

Keep credentials out of source archives and dependency files. Prefer the cloud build and secret-management mechanisms documented for your organization, and test a clean build that has no access to your personal credential cache.

Troubleshooting shared-library failures

Symptom Likely cause Fix
Import or module-not-found error after deployment The dependency declaration or shared package was outside the deployed source root. Move the declaration and package into the source root, or publish/vendor the package using the runtime’s supported method.
Works locally, fails in the cloud build Your workstation supplied an undeclared package or cached credentials. Build from a clean environment, declare every import, and configure registry access explicitly.
Private package download times out The managed build cannot reach or authenticate to the private registry. Use the registry configuration documented for the language, or vendor the dependency. For Go, follow the documented private-module vendor process.
Function starts but shared code is stale A lock/checksum file or vendored copy was not updated. Refresh the dependency through the language’s package tool, review the resulting diff, and redeploy.
Local HTTP test passes but production event fails The test used the wrong trigger signature. Run the Functions Framework with the HTTP or CloudEvent shape that the trigger actually sends.
Deployment rejected or runtime unavailable The selected runtime version changed support status. Check the current runtime support page, choose a supported identifier, and follow the current deployment guide.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, reliability, and maintenance choices

  • Keep shared packages focused. A large utility package can pull in transitive dependencies that every function must build and load.
  • Pin deliberately. Lock or checksum files improve repeatability; schedule updates so security fixes are not silently missed.
  • Choose vendoring for control, not habit. It improves offline reproducibility but increases source size and requires a refresh when a library changes.
  • Separate deployment units. Sharing source does not mean every function should deploy every feature. Keep each function’s dependency set to what its handler needs.
  • Re-test after runtime changes. A new language runtime can alter supported package versions or build behavior even when your application code is unchanged.

Or skip the browser setup

If you also need automated website screenshots for documentation, visual checks, or release records, ScreenshotNeo provides a single HTTP endpoint instead of maintaining browser automation. It accepts cookie and consent banners before capture, removes more than 60 known consent platforms plus newsletter popups and chat widgets, and bills only clean shots: bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing. The response identifies the result with X-Page-Verdict and X-Billed headers.

One call returns PNG, JPEG, WebP, or PDF. The API supports full-page and element captures, device presets or custom viewports, dark mode, retina scale, PDF page settings, custom CSS and JavaScript, clicks, waits, blocked requests, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, TTL caching, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

See the ScreenshotNeo API documentation for parameters and authentication. This cURL request saves a WebP screenshot:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

The same request in Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 screenshots each month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can I use one dependency file for functions written in different languages?

No. Each runtime reads its own dependency declaration and build metadata. Maintain a language-appropriate declaration for every function.

When should a Go project use vendor instead of modules?

Use the documented vendor approach when a dependency cannot be fetched by a manager or when your build must work without public-network access.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where can I verify whether a runtime version is still supported?

Check Google’s live runtime-support table before selecting or upgrading a runtime: Runtime support.

The Bottom Line

Declare shared code in the dependency format for the function’s runtime, keep private packages reachable through a supported registry or vendor directory, test with the Functions Framework, and verify runtime support before deployment.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.