[Yandex Cloud documentation](../../../index.md) > [Yandex DataSphere](../../index.md) > [Step-by-step guides](../index.md) > Working with resources > Working with secrets

# Working with secrets

[Secrets](../../concepts/secrets.md) enable storing sensitive data in encrypted form and using it securely within your project code.

## Creating a secret {#create}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![secret](../../../_assets/console-icons/shield-check.svg)**Secret**.
1. Click **Create**.
1. In the **Name** field, enter a name for the secret.

   The name may contain uppercase and lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character cannot be a hyphen or underscore. The name must be 2 to 63 characters long.

1. In the **Value** field, enter a value to store in encrypted form.
1. Click **Create**. You will see a page with detailed info on the secret you created.

## Sharing a secret {#share}

{% note info %}

You can only share resources within a single organization, between communities created in the same [availability zone](../../../overview/concepts/geo-scope.md).

{% endnote %}

To share a secret within a community, you need the `Editor` role in the project and the `Developer` role in the community. To learn more about roles in DataSphere, see [Access management in DataSphere](../../security/index.md).

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![secret](../../../_assets/console-icons/shield-check.svg)**Secret**.
1. Select the secret from the list.
1. Go to the **Access** tab.
1. Enable the visibility option next to the name of the community you want to share the secret in.

To make a secret available for use in a different project, the project editor needs to [add](../projects/use-shared-resource.md) that secret on the **Shared** tab.

## Accessing a secret from a project cell {#call}

Once you create a secret, you can use it in project cells as an environment variable.

{% list tabs group=programming_language %}

- Python {#python}

   ```python
   import os
   os.environ # Getting a list of all environment variables
   os.environ['<secret_name>'] # Accessing <secret_name> from environment variables
   ```

- Bash {#bash}

   ```bash
   #!:bash
   printenv <secret_name>
   ```

{% endlist %}

## Copying a secret {#copy}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![secret](../../../_assets/console-icons/shield-check.svg) **Secret**.
1. In the list of secrets, choose the one you want to copy to your project, click ![options](../../../_assets/console-icons/ellipsis.svg), and select **Clone**.
1. Edit the name and contents of the secret to copy.
1. Click **Create**. You will see a page with detailed info on the secret you created.

A copied secret is not linked to the original: you can edit and delete the former without affecting the latter.

## Updating a secret {#change}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![secret](../../../_assets/console-icons/shield-check.svg) **Secret**.
1. In the list of secrets, choose the one you want to update, click ![options](../../../_assets/console-icons/ellipsis.svg), and select **Edit**.
1. Update the secret by editing its name and contents.
1. Click **Save**.

You cannot edit a secret created in a different project, but you can edit its [copy](secrets.md#copy).

## Deleting a secret {#delete}

1. Select the project in your community or on the DataSphere [home page](https://datasphere.yandex.cloud) in the **Recent projects** tab.
1. Under **Project resources**, click ![secret](../../../_assets/console-icons/shield-check.svg) **Secret**.
1. In the list of secrets, choose the one you want to delete, click ![options](../../../_assets/console-icons/ellipsis.svg), and select **Delete**.
1. Click **Confirm**.

You will see a message saying that the secret has been deleted.

{% note warning %}

In fact, [resource deletion](../../../overview/concepts/data-deletion.md) can take up to 72 hours.

{% endnote %}