forked from eval-protocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_api_key.py
More file actions
31 lines (24 loc) · 869 Bytes
/
Copy pathgenerate_api_key.py
File metadata and controls
31 lines (24 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import argparse
import secrets
def generate_api_key(length: int = 32) -> str:
"""
Generates a cryptographically strong random string to be used as an API key.
Args:
length: The desired length of the API key in bytes.
The resulting hex string will be twice this length.
Default is 32 bytes, resulting in a 64-character hex string.
Returns:
A hex-encoded secure random string.
"""
return secrets.token_hex(length)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a secure API key.")
parser.add_argument(
"--length",
type=int,
default=32,
help="Length of the key in bytes (default: 32, produces a 64-char hex string).",
)
args = parser.parse_args()
api_key = generate_api_key(args.length)
print(api_key)