Environments

envless.environments.create()

Create an environment in a project

def create(
    project: str,
    body: EnvironmentCreate,
    *,
    product: str | None = None,
    timeout: float | None = None,
) -> EnvironmentResource

Creates an environment inside a project. The API requires both name and slug, so always send a slug: it is slugified server-side before validation and has to be free within the project.

The body is parsed and validated before the project is resolved, so a bad name returns 400 even when the project reference is wrong too. The allowance is counted per project, not per workspace the way products and projects are, and it is checked before the slug conflict, so a project that is already at its limit fails with 402 no matter which slug you picked.

Example

from envless import envless

environment = envless.environments.create(
    'api', {'name': 'Production', 'slug': 'production'}
)

print(environment['id'], environment['slug'])

Parameters

ParameterTypeRequiredDescription
projectstrYesProject slug or uniqueId that will own the environment.
body['name']strYesDisplay name, 2 to 50 characters.
body['slug']strYesLowercase hyphenated slug, unique inside the project.
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, the full shape that carries exposed and updatedAt.

Worth knowing

  • exposed is always False here; publishing a feed is a separate expose call.
  • On a 402 the error resource names the allowance that was hit and its message states the limit. The response body also carries limit and current, which EnvlessApiError does not expose.

Required scopes

environments:write

Underlying endpoint

POST /projects/{slug}/environments

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

In TypeScript

envless.environments.create()

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