Environments

envless.environments.duplicate()

Copy an environment and its variables

def duplicate(
    project: str,
    environment: str,
    *,
    product: str | None = None,
    timeout: float | None = None,
) -> EnvironmentResource

Copies an environment and all of its variables, ciphertext included, into the same project in one transaction. There is no request body. Version history is not copied, so the clone starts with nothing published.

The copy is named <name> (Copy), truncated to 50 characters, and its slug comes from that name with a -2, -3 suffix until one is free, falling back to a random six-character suffix after enough collisions. Never guess the resulting slug, read it off the returned resource. The per-project allowance is checked before any copying starts, so a 402 or a 409 leaves nothing half-created.

Example

from envless import envless

clone = envless.environments.duplicate('api', 'production')

print(clone['slug'])

Parameters

ParameterTypeRequiredDescription
projectstrYesProject slug or uniqueId that owns the source environment.
environmentstrYesSlug of the environment to copy; ids are not accepted.
productstrNoProduct slug that disambiguates an ambiguous project slug.
timeoutfloatNoSeconds each attempt of this call may take, the response body included, before it raises EnvlessNetworkError with is_timeout set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

EnvironmentResource for the new copy, including its generated slug.

Worth knowing

  • The key needs both environments:write and variables:write, since variables move with the environment.
  • Values are copied as stored ciphertext, so the copy decrypts with the same passphrase as the source.
  • exposed is False on the copy whatever the source was set to.

Required scopes

environments:write and variables:write

Underlying endpoint

POST /projects/{slug}/environments/{environmentSlug}/duplicate

Request and response schema, every error code, and a live playground.

In TypeScript

envless.environments.duplicate()

The same method in @goenvless/sdk, with the same request, retries and errors.