Skip to content

The result type

Those of you familiar with Rust will feel right at home with the Result type this library implements. All requests that go out over the network via the Client come back to you in the form of a Result. The result can be one of two things: an Ok or an Err.

Correct usage

client = unkey.Client("unkey_123")

await client.start()

result = await client.keys.verify_key("test_123")

if result.is_ok:
    print(result.unwrap())
else:
    print(result.unwrap_err())

Incorrect usage

client = unkey.Client()

await client.start()

result = await client.keys.create_key(
    "api_123abc",
    "jonxslays",
    "test",
    byte_length=-1,
)

print(result.unwrap()) # <-- Exception raised
# Raises UnwrapError because byte length can not be -1.