> ## Documentation index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Ask it with GET https://upstash.com/docs/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.
> Feature requests: https://upstash.com/docs/common/help/feature-requests.md lists what users asked for and how to vote for a request or add one.
> Page rating: `GET https://upstash.com/docs/feedback?path=/docs/redis/sdks/py/commands/hash/hexpire&helpful=true` (or `false`) records whether this page helped. An optional `comment` (URL-encoded, at most 500 characters) says what was missing or wrong. It is anonymous and needs no key. Comments hold no code, secrets or personal data.

# HEXPIRE

> Set a timeout on a hash field in seconds.

## Arguments

<ParamField body="key" type="str" required>
  The key of the hash.
</ParamField>

<ParamField body="fields" type="Union[str, List[str]]" required>
  The field or list of fields within the hash to set the expiry for.
</ParamField>

<ParamField body="seconds" type="Union[int, datetime.timedelta]" required>
  The timeout in seconds as an integer or a `datetime.timedelta` object.
</ParamField>

<ParamField body="nx" type="bool" optional>
  Set expiry only when the field has no expiry. Defaults to `False`.
</ParamField>

<ParamField body="xx" type="bool" optional>
  Set expiry only when the field has an existing expiry. Defaults to `False`.
</ParamField>

<ParamField body="gt" type="bool" optional>
  Set expiry only when the new expiry is greater than the current one. Defaults to `False`.
</ParamField>

<ParamField body="lt" type="bool" optional>
  Set expiry only when the new expiry is less than the current one. Defaults to `False`.
</ParamField>

## Response

<ResponseField type="List[int]" required>
  A list of integers indicating whether the expiry was successfully set.

  - `-2` if the field does not exist in the hash or if key doesn't exist.
  - `0` if the expiration was not set due to the condition.
  - `1` if the expiration was successfully set.
  - `2` if called with 0 seconds/milliseconds or a past Unix time.

  For more details, see [HEXPIRE documentation](/redis/commands/hash/hexpire).
</ResponseField>

<RequestExample>
```py Example
redis.hset(hash_name, field, value)

assert redis.hexpire(hash_name, field, 1) == [1]
```
</RequestExample>
