File size: 704 Bytes
e99119f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import secrets
import string

def generate_api_key(length=32):
    """Generate a random, URL-safe text string starting with 'fs_'."""
    # Generate a random string of the desired length minus the prefix length
    random_part_length = length - 3 # 'fs_' is 3 characters
    if random_part_length < 0:
        raise ValueError("Length must be at least 3 to include the 'fs_' prefix.")
    alphabet = string.ascii_letters + string.digits
    random_string = ''.join(secrets.choice(alphabet) for i in range(random_part_length))
    return "fs_" + random_string

# Generate an API key with a length of 40 (including the 'fs_' prefix)
api_key = generate_api_key(40)
print("Generated API Key:")
print(api_key)