Timestamp and Numeric Representation: Now, the package incorporates a time-based and date-based hashing mechanism, adding an extra layer of security to your API keys. It captures the current timestamp and numeric representation of the key generation process, creating a unique identifier that's closely tied to the moment it was generated. This feature adds an element of time-based uniqueness to your keys, making them even more secure and less predictable.
This package provides a convenient way to generate API keys using a secret, seed, and an optional include keyword. The generated keys are unique and secure, making them suitable for use in a variety of applications.
The package supports generating API keys using a variety of methods such as UUID v5 and SHA-256 algorithm. The keys are generated using a combination of seed, secret, and include keyword. Additionally, the package allows you to insert the include keyword at a random position in the seed which will make it more difficult to guess.
It is important to keep the secret used to generate the keys secure and not share it with unauthorized parties. Additionally, the package can only be used for legitimate and legal purposes.
Please keep in mind that, even though this package provides a secure way to generate API keys, it is still important to use other security measures such as rate limiting, IP whitelisting, and encryption to protect your API and the data it accesses.
By using this package, you agree to take all necessary precautions to protect the data and resources accessed with the keys from unauthorized access or misuse. It is recommended to consult with a security expert before using this package or handling sensitive data.
This package generates API keys that can be used to access sensitive data or resources. By using this package, you agree to keep the secret used to generate the keys secure and not share it with unauthorized parties. Additionally, the package can only be used for legitimate and legal purposes.
Please be aware that the package may cause a security risk if not used properly. The authors of this package cannot be held responsible for any unauthorized access or misuse of the keys generated by this package.
It is the user's responsibility to ensure the security of the keys and the protection of the data. It is recommended to consult with a security expert before using this package or handling sensitive data.
By using this package, you agree to take all necessary precautions to protect the data and resources accessed with the keys from unauthorized access or misuse.
To install your package, you can use the pip package manager by running the following command in your command line:
pip install generateApiKeyThe simplest way to get a secure key — no arguments, no await:
from generateApiKey import generate_api_key
api_key = generate_api_key() # 'uYTvAuzrTHAeU202ScbN6jV8kxIMogDf'That's it. Everything below is optional.
generate_api_key(length=48) # longer key
generate_api_key(prefix="sk") # 'sk-gRsNbb2lQ1cZxoT3...'
generate_api_key(dashes=True) # 'GdBA-6DhM-M3Fv-g99C...'
generate_api_key(charset="hex", length=32) # hex only
generate_api_key(charset="base58") # no ambiguous 0/O/I/l
generate_api_key(charset="ABC123", length=10) # your own alphabet
generate_api_key(case="upper", charset="alphabetic")Pass a preset name or a literal string of characters to charset:
| Preset | Characters |
|---|---|
alphanumeric (default) |
A-Z a-z 0-9 |
base62 |
A-Z a-z 0-9 |
base58 |
base62 minus 0 O I l |
base64url |
A-Z a-z 0-9 - _ |
alphabetic |
A-Z a-z |
numeric |
0-9 |
hex |
0-9 a-f |
base16 |
0-9 A-F |
Set expiry (minutes). The returned key is a string but also carries expiry metadata:
key = generate_api_key(expiry=60)
headers = {"Authorization": key} # works — it's a str
key.expires_at # unix timestamp
key.is_expired # False (until 60 min pass)Provide both secret and seed to derive the key deterministically from them
(HMAC-SHA256). A random salt still makes each generated key unique:
generate_api_key("mysecret", "user-42", length=20, include="prod")The library is synchronous by default. When you need an awaitable:
from generateApiKey import generate_api_key_async
api_key = await generate_api_key_async(length=48, prefix="sk")The original
await generateApiKey(secret, seed, ...)still works unchanged for backwards compatibility, butgenerate_api_keyis recommended.
try:
api_key = generate_api_key(length=32)
except ValueError as e:
print(e) # e.g. bad length, or only one of secret/seed givenAll parameters are optional. Call generate_api_key() with nothing for a secure default.
| Parameter | Type | Default | Description |
|---|---|---|---|
secret |
str |
None |
Optional secret. Given with seed, the key is HMAC-derived instead of random. |
seed |
str |
None |
Optional per-key value, used together with secret. |
length |
int |
32 |
Number of characters in the key body. |
charset |
str |
"alphanumeric" |
Preset name (see table) or a literal string of allowed characters. |
case |
str |
"mixed" |
"mixed", "lower" or "upper". Affects letters only. |
prefix |
str |
None |
Prefix joined with separator, e.g. sk-.... |
separator |
str |
"-" |
String between prefix and key. |
dashes |
bool |
False |
Group the key with dashes for readability. |
dash_group |
int |
4 |
Group size when dashes=True. |
include |
str |
None |
Extra value mixed into a derived key (needs secret + seed). |
expiry |
int |
None |
Expiry in minutes; sets .expires_at / .is_expired. |
Returns an ApiKey — a str subclass, so it works anywhere a string does.
By using this package, you are solely liable for any legal issues that may arise from its unauthorized use or misuse, as well as any security risks that may result from not properly securing the secret key used to generate the API keys.
This package is provided as is, without any warranties or guarantees of any kind. We are not liable for any damages or losses that may result from its use. We reserve the right to change or discontinue the package at any time without notice.
We encourage you to use the package responsibly, and to report any security issues or bugs you may encounter.
Made with ❤️ , Happy coding! 🚀