> ## 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.

# Client and authentication

> Configure the Python SDK client and log in to Infisical.

Every call to Infisical goes through an `InfisicalSDKClient`. You create the client once, log it in as a [machine identity](https://infisical.com/docs/documentation/platform/identities/machine-identities.md), and then use it for every request.

## Create a client

Create the client with the URL of your Infisical instance in `host`.

```python US Cloud theme={"dark"}
from infisical_sdk import InfisicalSDKClient

client = InfisicalSDKClient(host="https://app.infisical.com")
```

```python EU Cloud theme={"dark"}
from infisical_sdk import InfisicalSDKClient

client = InfisicalSDKClient(host="https://eu.infisical.com")
```

```python Self-hosted theme={"dark"}
from infisical_sdk import InfisicalSDKClient

client = InfisicalSDKClient(host="<your-instance-url>")
```

**Parameters:**

**host** `str` *required*

The URL of your Infisical instance.

**token** `str`

An access token to send with every request. If you set it, you don't need to log in.

**cache\_ttl** `int` (default: 60)

The number of seconds to cache secrets for, or `None` to turn off the cache.

The client caches the secrets that `get_secret_by_name` and `list_secrets` return. Creating, updating, or deleting a secret through the client clears the cached secrets. The cache doesn't see changes made anywhere else, so a secret can be up to `cache_ttl` seconds old.

The cache keeps one copy of each secret, whatever `version`, `view_secret_value`, `include_imports`, or `expand_secret_references` you pass to `get_secret_by_name`. If you pass any of them, set `cache_ttl` to `None`.

The cache runs a background thread. To stop the thread when you're done with the client, call `client.close()`, or create the client in a `with` statement:

```python theme={"dark"}
with InfisicalSDKClient(host="https://app.infisical.com") as client:
    ...
```

## Log in

The client logs in with one of the machine identity's [authentication methods](https://infisical.com/docs/documentation/platform/identities/machine-identities.md#authentication-methods). After the client logs in, it sends the access token it got with every request.

### Universal Auth

```python theme={"dark"}
import os

client.auth.universal_auth.login(
    client_id=os.environ["INFISICAL_UNIVERSAL_AUTH_CLIENT_ID"],
    client_secret=os.environ["INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET"],
)
```

**Parameters:**

**client\_id** `str` *required*

The client ID of the machine identity's [Universal Auth](https://infisical.com/docs/documentation/platform/identities/universal-auth.md) configuration.

**client\_secret** `str` *required*

A client secret of the machine identity's Universal Auth configuration.

### AWS auth

If your application runs on AWS, it can log in through [AWS Auth](https://infisical.com/docs/documentation/platform/identities/aws-auth.md) with the AWS credentials it already has:

```python theme={"dark"}
client.auth.aws_auth.login(identity_id="<machine-identity-id>")
```

The SDK gets the details it needs from the AWS environment:

* **AWS credentials:** the same way boto3 does, such as from environment variables or the IAM role of an EC2 instance or Lambda function
* **AWS region:** from the `AWS_REGION` environment variable, or from the EC2 instance metadata if `AWS_REGION` isn't set

**Parameters:**

**identity\_id** `str` *required*

The ID of the machine identity. If you pass `None`, the SDK uses the value of the `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` environment variable.

### OIDC auth

If your identity provider issues OIDC tokens to your application, such as Okta or Auth0, the application can log in through [OIDC Auth](https://infisical.com/docs/documentation/platform/identities/oidc-auth/general.md):

```python theme={"dark"}
client.auth.oidc_auth.login(
    identity_id="<machine-identity-id>",
    jwt="<oidc-token>",
)
```

**Parameters:**

**identity\_id** `str` *required*

The ID of the machine identity.

**jwt** `str` *required*

The OIDC token from your identity provider.

### LDAP auth

To log in with an LDAP username and password through [LDAP Auth](https://infisical.com/docs/documentation/platform/identities/ldap-auth/general.md):

```python theme={"dark"}
import os

client.auth.ldap_auth.login(
    identity_id="<machine-identity-id>",
    username="<ldap-username>",
    password=os.environ["LDAP_PASSWORD"],
)
```

**Parameters:**

**identity\_id** `str` *required*

The ID of the machine identity.

**username** `str` *required*

The LDAP username.

**password** `str` *required*

The LDAP password.

### Access token

If your application gets an access token some other way, such as through [Token Auth](https://infisical.com/docs/documentation/platform/identities/token-auth.md), give the token to the client:

```python theme={"dark"}
client.auth.token_auth.login(token="<access-token>")
```

**Parameters:**

**token** `str` *required*

The access token, without the `Bearer` prefix.

To read the token that the client uses, call `client.get_token()`.

## Access token expiry

The SDK doesn't renew the access token. The token expires after the **Access Token TTL** set in the machine identity's auth method. If your application runs longer than that, log in again before the token expires.

The `login` methods except `token_auth.login` return the token's details, including its lifetime in seconds in `expiresIn`:

```python theme={"dark"}
response = client.auth.universal_auth.login(client_id=..., client_secret=...)
print(response.expiresIn)
```


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