Skip to main content

Downloads Supported Versions GitHub PyPI PyPI - Downloads Downloads Upload to PIP PyPI - Format

API Key Generation Package

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.

Privacy Policy

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.

Installation

To install your package, you can use the pip package manager by running the following command in your command line:

pip install generateApiKey

Quick start

The 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.

Common recipes

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")

Charsets

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

Expiring keys

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)

Derived keys (secret + seed)

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")

Async is optional

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, but generate_api_key is recommended.

Error handling

try:
    api_key = generate_api_key(length=32)
except ValueError as e:
    print(e)   # e.g. bad length, or only one of secret/seed given

Parameters

All 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.

Fair Use Policy:

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! 🚀

Metadata

Release files for generateApiKey 0.4.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generateApiKey 0.4.8
File Size Uploaded
generateapikey-0.4.8.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for generateApiKey 0.4.8
File Interpreter ABI Platform
generateapikey-0.4.8-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / generateapikey-0.4.8.tar.gz

Download URL generateapikey-0.4.8.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7a0015bb16063a9c8c3013ffc813a390e48a4fbfcf2fe9e197a9cdc1b3e7fd08
BLAKE2b-256 checksum
How to use checksums
6b2ac7ce3d13c7fc217bbce46be5f9a4e396b3d465efbea0f66c2d4e5096fd20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / generateapikey-0.4.8-py3-none-any.whl

Download URL generateapikey-0.4.8-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4582992448b33b167ac7a1fe383efb97e8dce082a29049426490d45da94609c
BLAKE2b-256 checksum
How to use checksums
244571302b6b121f6064a92f168683389c730c6382a0ef98fe5da75624a02749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.4.8 This release

2 release files

0.4.7

2 release files

0.4.5

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page