Migrating to version 1.0.3 or above
We have recently rolled out our first stable version of the SDK, version1.0.3 and above.
The 1.0.3 version comes with a few key changes that may change how you’re using the SDK.
-
Removal of
rest: The SDK no longer exposes the entire Infisical API. This was necessary as we have moved away from using an OpenAPI generator approach. We aim to add support for more API resources in the near future. If you have any specific requests, please open an issue. -
New response types: The 1.0.3 release uses return types that differ from the older versions. The new return types such as
BaseSecret, are all exported from the Infisical SDK. -
Property renaming: Some properties on the responses have been slightly renamed. An example of this would be that the
secret_keyproperty on theget_secret_by_name()method, that has been renamed tosecretKey.
1.0.3 or above.
You can refer to our legacy documentation if need be.
Requirements
Python 3.7+Installation
Getting started
InfisicalSDKClient parameters
TheInfisicalSDKClient takes the following parameters, which are used as a global configuration for the lifetime of the SDK instance.
- host (
str, Optional): The host URL for your Infisical instance. Defaults tohttps://app.infisical.com. - token (
str, Optional): Specify an authentication token to use for all requests. If provided, you won’t need to call any of theauthmethods. Defaults toNone - cache_ttl (
int, Optional): The SDK has built-in client-side caching for secrets, greatly improving response times. By default, secrets are cached for 1 minute (60 seconds). You can disable caching by settingcache_ttltoNone, or adjust the duration in seconds as needed.
Core methods
The SDK methods are organized into the following high-level categories:auth: Handles authentication methods.secrets: Manages CRUD operations for secrets.dynamic_secrets: Manages dynamic secrets and leases.kms: Perform cryptographic operations with Infisical KMS.folders: Manages folder-related operations.agent_vault: Manages Agent Vault sessions and proxies.
auth
The Auth component provides methods for authentication:
Universal auth
AWS auth
OIDC auth
identity_id(str): The ID of the OIDC identity configuration in Infisical.jwt(str): The OIDC JWT token obtained from your identity provider.
LDAP auth
identity_id(str): The ID of the LDAP identity configuration in Infisical.username(str): Your LDAP username.password(str): Your LDAP password.
Please note that this authentication method requires LDAP credentials. Please
read more about this
authentication method.
Token auth
token(str): The access token to authenticate with. This can be a machine identity token or a user access token.
secrets
This sub-class handles operations related to secrets:
List secrets
project_id(str): The ID of your project.project_slug(str): The slug of your project.environment_slug(str): The environment in which to list secrets (e.g., “dev”).secret_path(str): The path to the secrets.expand_secret_references(bool): Whether to expand secret references.view_secret_value(bool): Whether or not to include the secret value in the response. If set to false, thesecretValuewill be masked with<hidden-by-infisical>. Defaults to true.recursive(bool): Whether to list secrets recursively.include_imports(bool): Whether to include imported secrets.tag_filters(List[str]): Tags to filter secrets.
project_id or project_slug is required. If both are provided, project_id takes precedence.
Returns:
ListSecretsResponse: The response containing the list of secrets.
Create secret
secret_name(str): The name of the secret.project_id(str): The ID of your project.project_slug(str): The slug of your project.secret_path(str): The path to the secret.environment_slug(str): The environment in which to create the secret.secret_value(str): The value of the secret.secret_comment(str, optional): A comment associated with the secret.skip_multiline_encoding(bool, optional): Whether to skip encoding for multiline secrets.secret_reminder_repeat_days(Union[float, int], optional): Number of days after which to repeat secret reminders.secret_reminder_note(str, optional): A note for the secret reminder.secret_metadata(List[Dict[str, Any]], optional): Metadata associated with the secret.tags_ids(List[str], optional): IDs of tags to associate with the secret.
project_id or project_slug is required. If both are provided, project_id takes precedence.
Returns:
BaseSecret: The response after creating the secret.
Update secret
current_secret_name(str): The current name of the secret.project_id(str): The ID of your project.project_slug(str): The slug of your project.secret_path(str): The path to the secret.environment_slug(str): The environment in which to update the secret.secret_value(str, optional): The new value of the secret.secret_comment(str, optional): An updated comment associated with the secret.skip_multiline_encoding(bool, optional): Whether to skip encoding for multiline secrets.secret_reminder_repeat_days(Union[float, int], optional): Updated number of days after which to repeat secret reminders.secret_reminder_note(str, optional): An updated note for the secret reminder.new_secret_name(str, optional): A new name for the secret.secret_metadata(List[Dict[str, Any]], optional): Metadata associated with the secret.tags_ids(List[str], optional): IDs of tags to associate with the secret.
project_id or project_slug is required. If both are provided, project_id takes precedence.
Returns:
BaseSecret: The response after updating the secret.
Get secret by name
secret_name(str): The name of the secret.project_id(str): The ID of your project.project_slug(str): The slug of your project.environment_slug(str): The environment in which to retrieve the secret.secret_path(str): The path to the secret.expand_secret_references(bool): Whether to expand secret references.view_secret_value(bool): Whether or not to include the secret value in the response. If set to false, thesecretValuewill be masked with<hidden-by-infisical>. Defaults to true.include_imports(bool): Whether to include imported secrets.version(str, optional): The version of the secret to retrieve. Fetches the latest by default.
project_id or project_slug is required. If both are provided, project_id takes precedence.
Returns:
BaseSecret: The response containing the secret.
Delete secret by name
secret_name(str): The name of the secret to delete.project_id(str): The ID of your project.project_slug(str): The slug of your project.environment_slug(str): The environment in which to delete the secret.secret_path(str): The path to the secret.
project_id or project_slug is required. If both are provided, project_id takes precedence.
Returns:
BaseSecret: The response after deleting the secret.
dynamic_secrets
This sub-class handles operations related to dynamic secrets. Dynamic secrets generate credentials on-demand with automatic expiration. For more information, see the Dynamic Secrets documentation.
Create dynamic secret
name(str): The name of the dynamic secret.provider_type(Union[DynamicSecretProviders, str]): The provider type (e.g.,DynamicSecretProviders.SQL_DATABASE).inputs(Dict[str, Any]): The provider-specific configuration inputs. See the Dynamic Secrets API documentation for provider-specific inputs.default_ttl(str): The default time to live for leases (e.g., “1h”, “30m”).max_ttl(str): The maximum time to live for leases (e.g., “24h”).project_slug(str): The slug of your project.environment_slug(str): The environment in which to create the dynamic secret.path(str, optional): The path where the dynamic secret will be created. Defaults to ”/”.metadata(List[Dict[str, str]], optional): Optional list of metadata items with ‘key’ and ‘value’.
DynamicSecret: The created dynamic secret.
Supported provider types
TheDynamicSecretProviders enum includes the following providers:
Get dynamic secret by name
name(str): The name of the dynamic secret.project_slug(str): The slug of your project.environment_slug(str): The environment in which to retrieve the dynamic secret.path(str, optional): The path to the dynamic secret. Defaults to ”/”.
DynamicSecret: The dynamic secret.
Update dynamic secret
name(str): The current name of the dynamic secret.project_slug(str): The slug of your project.environment_slug(str): The environment in which to update the dynamic secret.path(str, optional): The path to the dynamic secret. Defaults to ”/”.default_ttl(str, optional): The new default time to live for leases.max_ttl(str, optional): The new maximum time to live for leases.new_name(str, optional): The new name for the dynamic secret.inputs(Dict[str, Any], optional): Updated provider-specific configuration inputs.metadata(List[Dict[str, str]], optional): Updated metadata list with ‘key’ and ‘value’ items.username_template(str, optional): The new username template for the dynamic secret.
DynamicSecret: The updated dynamic secret.
Delete dynamic secret
name(str): The name of the dynamic secret to delete.project_slug(str): The slug of your project.environment_slug(str): The environment in which to delete the dynamic secret.path(str, optional): The path to the dynamic secret. Defaults to ”/”.is_forced(bool, optional): A boolean flag to delete the dynamic secret from Infisical without trying to remove it from the external provider. Defaults toFalse.
DynamicSecret: The deleted dynamic secret.
dynamic_secrets.leases
This sub-class handles operations related to dynamic secret leases. A lease represents a set of generated credentials with a specific TTL.
Create lease
Create a lease to generate credentials from a dynamic secret:dynamic_secret_name(str): The name of the dynamic secret to create a lease for.project_slug(str): The slug of your project.environment_slug(str): The environment in which to create the lease.path(str, optional): The path to the dynamic secret. Defaults to ”/”.ttl(str, optional): The time to live for the lease (e.g., “1h”, “30m”).
CreateLeaseResponse: Response containing:lease: The lease object with ID, expiration, and metadata.dynamicSecret: The associated dynamic secret.data: The generated credentials. The structure depends on the dynamic secret provider.
Get lease
lease_id(str): The ID of the lease to retrieve.project_slug(str): The slug of your project.environment_slug(str): The environment in which to retrieve the lease.path(str, optional): The path to the dynamic secret. Defaults to ”/”.
DynamicSecretLease: The lease with dynamicSecret included.
Renew lease
Extend the TTL of an existing lease:lease_id(str): The ID of the lease to renew.project_slug(str): The slug of your project.environment_slug(str): The environment in which to renew the lease.path(str, optional): The path to the dynamic secret. Defaults to ”/”.ttl(str, optional): The new time to live for the lease.
DynamicSecretLease: The renewed lease.
Revoke lease
Revoke a lease and its associated credentials:lease_id(str): The ID of the lease to revoke.project_slug(str): The slug of your project.environment_slug(str): The environment in which to revoke the lease.path(str, optional): The path to the dynamic secret. Defaults to ”/”.is_forced(bool, optional): A boolean flag to revoke the lease from Infisical without trying to remove it from the external provider. Defaults toFalse.
DynamicSecretLease: The revoked lease.
kms
This sub-class handles KMS related operations:
List KMS keys
project_id(str): The ID of your project.offset(int, optional): The offset to paginate from.limit(int, optional): The page size for paginating.order_by(KmsKeysOrderBy, optional): The key property to order the list response by.order_direction(OrderDirection, optional): The direction to order the list response in.search(str, optional): The text value to filter key names by.
ListKmsKeysResponse: The response containing the list of KMS keys.
Get KMS key by ID
key_id(str): The ID of the key to retrieve.
KmsKey: The specified key.
Get KMS key by name
key_name(str): The name of the key to retrieve.project_id(str): The ID of your project.
KmsKey: The specified key.
Create KMS key
name(str): The name of the key (must be slug-friendly).project_id(str): The ID of your project.encryption_algorithm(SymmetricEncryption): The encryption algorithm this key should use.description(str, optional): A description of your key.
KmsKey: The newly created key.
Update KMS key
key_id(str): The ID of the key to be updated.name(str, optional): The updated name of the key (must be slug-friendly).description(str): The updated description of the key.is_disabled(str): The flag to disable operations with this key.
KmsKey: The updated key.
Delete KMS key
key_id(str): The ID of the key to be deleted.
KmsKey: The deleted key.
Encrypt data with KMS key
key_id(str): The ID of the key to encrypt the data with.base64EncodedPlaintext(str): The plaintext data to encrypt (must be base64 encoded).
str: The encrypted ciphertext.
Decrypt data with KMS key
key_id(str): The ID of the key to decrypt the data with.ciphertext(str): The ciphertext returned from the encrypt operation.
str: The base64 encoded plaintext.
folders
This sub-class handles operations related to folders:
update_folder and delete_folder require infisicalsdk version 1.0.17 or newer.List folders
project_id(str): The ID of your project.environment_slug(str): The environment in which to list folders.path(str): The path to list folders from.recursive(bool, optional): Whether to list folders recursively from the specified path and downwards. Defaults toFalse.last_secret_modified(datetime, optional): The timestamp used to filter folders with secrets modified after the specified date. Defaults toNone.
ListFoldersResponse: The response containing the list of folders.
Create folder
name(str): The name of the folder to create.environment_slug(str): The slug of the environment to create the folder in.project_id(str): The ID of your project to create the folder in.path(str, optional): The path to create the folder in. Defaults to/.description(str, optional): An optional description label for the folder. Defaults toNone.
CreateFolderResponseItem: The response containing the created folder.
Get folder by ID
id(str): The ID of the folder to retrieve.
SingleFolderResponseItem: The response containing the folder details.
Update folder
folder_id(str): The ID of the folder to update. Folders can only be updated by ID, so uselist_foldersto look the ID up if you only know the name.name(str): The new name of the folder. This is required, so pass the folder’s current name to leave it unchanged.project_id(str): The ID of your project.environment_slug(str): The slug of the environment the folder is in.path(str, optional): The parent path the folder is in. Defaults to/.description(str, optional): A new description for the folder. Omitting it leaves the existing description unchanged, so it can’t be used to clear one.
UpdateFolderResponseItem: The response containing the updated folder.
Delete folder
folder_id_or_name(str): The ID or the name of the folder to delete.project_id(str): The ID of your project.environment_slug(str): The slug of the environment the folder is in.path(str, optional): The parent path the folder is in. Defaults to/.force_delete(bool, optional): Whether to delete the folder even when it still contains secrets or subfolders. Defaults toFalse.
DeleteFolderResponseItem: The response containing the deleted folder. Unlike the other folder responses, it doesn’t include apathfield.
agent_vault.sessions
This sub-class manages Agent Vault sessions. A session lets an AI agent use the services in one access bundle until the session expires or someone revokes it.
What the client can do with sessions depends on the Agent Vault role of the user or machine identity that the client logs in as:
agent_vault requires infisicalsdk version 1.0.19 or newer.List sessions
scope(Union[AgentVaultSessionScope, str], optional): whose sessions to list, eitherAgentVaultSessionScope.MINE("mine") for the identity’s own sessions orAgentVaultSessionScope.ALL("all") for every session if the identity is an admin (defaults toAgentVaultSessionScope.MINE)statuses(List[Union[AgentVaultSessionStatus, str]], optional): the statuses to include, fromAgentVaultSessionStatus.ACTIVE("active"),AgentVaultSessionStatus.REVOKED("revoked"), andAgentVaultSessionStatus.EXPIRED("expired") (defaults to all three)search(str, optional): text to find in each session’s label, owner name, owner email, or access bundle namelimit(int, optional): the maximum number of sessions to return, from 1 to 100 (defaults to20)offset(int, optional): the number of sessions to skip (defaults to0)
ListAgentVaultSessionsResponse: the sessions insessions, and the total number of matching sessions intotalCount
Get session
session_id(str): the ID of the session
AgentVaultSession: the session
Create session
access_bundle(str): the name of the access bundle that the agent can use during the sessionttl(str, optional): how long the session lasts, as a duration of at least one minute such as30m,8h, or7d, or asneverfor a session that doesn’t expire (defaults to7d)label(str, optional): a short description of what the session is for, such asnightly deploy(up to 128 characters, without line breaks, tabs, or invisible characters)
CreatedAgentVaultSession: the new session, with the session token intoken(Infisical returns the token only once)
session.token to the agent, follow the steps in Start the agent with the session token.
Update session label
Add, change, or remove a session’s label, for example to record what the agent is working on. You can also change the label after the session expires or is revoked, unless the user or machine identity that owns the session was deleted.session_id(str): the ID of the sessionlabel(Optional[str]): the new label, orNoneto remove the label (up to 128 characters, without line breaks, tabs, or invisible characters)
AgentVaultSession: the updated session
Revoke session
Revoke a session when its agent finishes, even if the agent fails. The proxy stops attaching credentials for the session within one poll interval. If the agent can run longer than the client’s access token lasts, log in again before you revoke the session, because the SDK doesn’t renew the access token. Attl close to how long the agent runs limits how long the session stays active if the revoke fails.
session_id(str): the ID of the session
AgentVaultSession: the revoked session, withaccessBundlesset toNone(callgetfor the access bundle)
agent_vault.proxies
This sub-class manages Agent Vault proxies. A proxy attaches API credentials to the requests that agents send through it.
To use any method in this section except list, the client must log in as a user or machine identity with the Admin role in Agent Vault.
agent_vault requires infisicalsdk version 1.0.19 or newer.List proxies
search(str, optional): text to find in proxy namesorder_by(str, optional): what to sort the proxies by,nameorcreatedAt(defaults tocreatedAt)order_direction(str, optional): the direction to sort in,ascordesc(defaults todesc)limit(int, optional): the maximum number of proxies to return, from 1 to 100 (defaults to20)offset(int, optional): the number of proxies to skip (defaults to0)
ListAgentVaultProxiesResponse: the proxies inproxies, and the total number of matching proxies intotalCount
trafficPolicy, allowedHosts, pollInterval, and createdAt fields are None.
Create proxy
name(str): the name of the proxy, in lowercase letters, numbers, and hyphens (up to 64 characters)traffic_policy(Union[AgentVaultTrafficPolicy, str], optional): the proxy’s traffic policy, eitherAgentVaultTrafficPolicy.ANY_HOST("any-host") to forward requests to any host orAgentVaultTrafficPolicy.BUNDLE_HOSTS("bundle-hosts") to refuse requests to hosts that no service in the session’s access bundle covers (defaults toAgentVaultTrafficPolicy.ANY_HOST)allowed_hosts(Union[List[str], str], optional): hosts that agents can reach underAgentVaultTrafficPolicy.BUNDLE_HOSTSeven if no service covers them, as a list or a comma-separated string (see Exceptions)poll_interval(int, optional): how often, in seconds, the proxy checks its sessions and settings with Infisical, from 10 to 300 (defaults to60)
AgentVaultProxyWithTokenResponse: the proxy inproxy, and its proxy token inproxyToken(Infisical returns the token only once)
Update proxy
The proxy’s name and settings that you don’t pass stay as they are. If the proxy is running, it applies the changes within one poll interval.proxy_id(str): the ID of the proxyname(str, optional): the new name of the proxytraffic_policy(Union[AgentVaultTrafficPolicy, str], optional): the new traffic policyallowed_hosts(Union[List[str], str], optional): the new exceptions, which replace the current onespoll_interval(int, optional): the new poll interval in seconds, from 10 to 300clear_allowed_hosts(bool, optional): set toTrueto remove every exception (raises aValueErrorif you also passallowed_hosts)
AgentVaultProxy: the updated proxy
Delete proxy
proxy_id(str): the ID of the proxy
AgentVaultProxy: the deleted proxy, with values only inidandname
Rotate proxy token
Issue a new proxy token if the current one leaked, or to restore a proxy whose access you revoked. The old token stops working right away. To restart the proxy and its agents, follow the steps in Rotate a proxy’s token.proxy_id(str): the ID of the proxy
AgentVaultProxyWithTokenResponse: the proxy inproxy, and the new proxy token inproxyToken(Infisical returns the token only once)
Revoke proxy
Revoke a proxy’s access if you think a machine that runs the proxy is compromised. The proxy stops attaching credentials to requests until you rotate its token.proxy_id(str): the ID of the proxy
AgentVaultProxy: the revoked proxy