> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a secret

> Create a secret in a folder with the Python SDK.

`client.secrets.create_secret_by_name()` creates a secret in a folder in an environment of a project. The machine identity needs a [role](https://infisical.com/docs/documentation/platform/access-controls/role-based-access-controls.md#project-level-access-controls) in the project that can change secrets, such as **Member**.

## Parameters

**secret\_name** `str` *required*

The name of the secret.

**project\_id** `str`

The ID of the project. Pass `project_id` or `project_slug`. If you pass both, the SDK uses `project_id`.

**project\_slug** `str`

The slug of the project.

**environment\_slug** `str` *required*

The slug of the environment, such as `dev`.

**secret\_path** `str` *required*

The path of the folder, such as `/` or `/backend`.

**secret\_value** `str` *required*

The value of the secret.

**secret\_comment** `str`

A comment that Infisical shows with the secret.

**tags\_ids** `List[str]`

The IDs of the tags to add to the secret.

**secret\_metadata** `List[Dict[str, Any]]`

Key-value pairs to store with the secret, each a dictionary with `key` and `value`.

**skip\_multiline\_encoding** `bool` (default: False)

Whether to store a multi-line value without encoding its line breaks.

**secret\_reminder\_note** `str`

The note that Infisical sends with each reminder to rotate the secret.

**secret\_reminder\_repeat\_days** `int`

The number of days between reminders, at least 1.

## Returns

**secret** `BaseSecret`

The new secret, with its `id`, `secretKey`, `secretValue`, `secretComment`, `environment`, `type`, and `version`. To get its tags and metadata, call [`get_secret_by_name`](https://infisical.com/docs/sdks/languages/python/secrets/get-secret).

```python Basic theme={"dark"}
secret = client.secrets.create_secret_by_name(
    secret_name="STRIPE_KEY",
    project_id="<project-id>",
    environment_slug="dev",
    secret_path="/",
    secret_value="<stripe-key>",
)
```

```python With a comment and tags theme={"dark"}
secret = client.secrets.create_secret_by_name(
    secret_name="STRIPE_KEY",
    project_id="<project-id>",
    environment_slug="dev",
    secret_path="/backend",
    secret_value="<stripe-key>",
    secret_comment="Test mode key",
    tags_ids=["<tag-id>"],
    secret_metadata=[{"key": "owner", "value": "billing"}],
)
```

```python With a rotation reminder theme={"dark"}
secret = client.secrets.create_secret_by_name(
    secret_name="STRIPE_KEY",
    project_id="<project-id>",
    environment_slug="prod",
    secret_path="/",
    secret_value="<stripe-key>",
    secret_reminder_note="Roll the key in the Stripe dashboard",
    secret_reminder_repeat_days=90,
)
```

```json Response theme={"dark"}
{
  "id": "9d2f1e4c-7b3a-4c6d-8e5f-0a1b2c3d4e5f",
  "_id": "9d2f1e4c-7b3a-4c6d-8e5f-0a1b2c3d4e5f",
  "workspace": "5e8d7c6b-4a3f-4e2d-9c1b-0a9f8e7d6c5b",
  "environment": "dev",
  "secretKey": "STRIPE_KEY",
  "secretValue": "<stripe-key>",
  "secretComment": "",
  "type": "shared",
  "version": 1,
  "secretReminderNote": null,
  "secretReminderRepeatDays": null,
  "skipMultilineEncoding": false,
  "createdAt": "2026-12-02T10:21:44.130Z",
  "updatedAt": "2026-12-02T10:21:44.130Z"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.