prefect_hex.credentials
Credential classes used to perform authenticated interactions with Hex
HexCredentials
pydantic-model
Block used to manage Hex authentication.
Attributes:
Name | Type | Description |
---|---|---|
domain |
str |
Domain to make API requests against. |
token |
SecretStr |
The token to authenticate with Hex. |
Examples:
Load stored Hex credentials:
from prefect_hex import HexCredentials
hex_credentials_block = HexCredentials.load("BLOCK_NAME")
Source code in prefect_hex/credentials.py
class HexCredentials(Block):
"""
Block used to manage Hex authentication.
Attributes:
domain: Domain to make API requests against.
token: The token to authenticate with Hex.
Examples:
Load stored Hex credentials:
```python
from prefect_hex import HexCredentials
hex_credentials_block = HexCredentials.load("BLOCK_NAME")
```
"""
_block_type_name = "Hex Credentials"
_logo_url = "https://images.ctfassets.net/gm98wzqotmnx/3biMverMLGiDA7y5fkqKZF/4b7747052b59fa8182a9686b88ea9541/Hex_Purple__for_light_backgrounds_.png?h=250" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-hex/credentials/#prefect_hex.credentials.HexCredentials" # noqa
domain: str = Field(
default="app.hex.tech", description="Domain to make API requests against."
)
token: SecretStr = Field(default=..., description="Token used for authentication.")
def get_client(self) -> AsyncClient:
"""
Gets a Hex REST AsyncClient.
Returns:
A Hex REST AsyncClient.
Example:
Gets a Hex REST AsyncClient.
```python
from prefect import flow
from prefect_hex import HexCredentials
@flow
def example_get_client_flow():
token = "consumer_key"
hex_credentials = HexCredentials(token=token)
client = hex_credentials.get_client()
return client
example_get_client_flow()
```
"""
client_kwargs = {
"base_url": f"https://{self.domain}/api/v1",
"headers": {"Authorization": f"Bearer {self.token.get_secret_value()}"},
}
client = AsyncClient(**client_kwargs)
return client
domain: str
pydantic-field
Domain to make API requests against.
token: SecretStr
pydantic-field
required
Token used for authentication.
__json_encoder__
special
staticmethod
partial(func, args, *keywords) - new function with partial application of the given arguments and keywords.
get_client
Gets a Hex REST AsyncClient.
Returns:
Type | Description |
---|---|
AsyncClient |
A Hex REST AsyncClient. |
Examples:
Gets a Hex REST AsyncClient.
from prefect import flow
from prefect_hex import HexCredentials
@flow
def example_get_client_flow():
token = "consumer_key"
hex_credentials = HexCredentials(token=token)
client = hex_credentials.get_client()
return client
example_get_client_flow()
Source code in prefect_hex/credentials.py
def get_client(self) -> AsyncClient:
"""
Gets a Hex REST AsyncClient.
Returns:
A Hex REST AsyncClient.
Example:
Gets a Hex REST AsyncClient.
```python
from prefect import flow
from prefect_hex import HexCredentials
@flow
def example_get_client_flow():
token = "consumer_key"
hex_credentials = HexCredentials(token=token)
client = hex_credentials.get_client()
return client
example_get_client_flow()
```
"""
client_kwargs = {
"base_url": f"https://{self.domain}/api/v1",
"headers": {"Authorization": f"Bearer {self.token.get_secret_value()}"},
}
client = AsyncClient(**client_kwargs)
return client