Skip to main content

A tiny, secure key generator.

Reason this release was yanked:

forgot to update readme

Project description

On PyPI Downloads Total Downloads Python Version License

TinyGenKey

A tiny, secure, and easy-to-use key generator in Python. Generate cryptographically strong keys for your needs.


Features

  • Cryptographically secure keys using os.urandom
  • Customizable alphabet, length, prefix, and suffix
  • Lightweight and dependency-free
  • Type-hinted for modern Python

Installation

pip install tinygenkey

Usage

import tinygenkey as tgk


# Generate a default 42-character key
key = tgk.gen_key()
print(key)

# Generate a key with a prefix and suffix
key2 = tgk.gen_key(prefix="user_", suffix="_end", length=16)
print(key2)

# Use a custom alphabet
custom_alphabet = list("ABC123")
key3 = tgk.gen_key(alphabet=custom_alphabet, length=8)
print(key3)

keys_seq()

This function returns a list of keys, determined with argument count and customized with **kwargs.

api_key = tgk.keys_seq(5) # Generates 5 keys

new_tokens = tgk.keys_seq(5, prefix="new_", suffix=f"_{tgk.keys_gen(length=6)}", preset="hex")

# Align with keys_align()
print(tgk.keys_align(new_tokens))

keys_align()

Separates a list of tokens with a passed separator argument (default is newline \n). Examples could be seen on keys_seq()

keys_verify()

A powerful tool to validate keys against character sets, length requirements, and more:

result = tgk.keys_verify(
    "api_abc123_key",
    preset="hex",
    min_length=8,
    max_length=20,
    prefix="api_",
    suffix="_key"
)

if result["valid"]:
    print("[v] Valid key!")
else:
    print("[x] Issues found:")
    for reason in result["reasons"]:
        print(f"  - {reason}")
    
    if result["hints"]:
        print("\nHints:")
        for hint in result["hints"]:
            print(f"  {hint}")

Advanced Usage

Recursive Key Generation

Create structured, hierarchical keys by cleanly nesting keys_gen() (or outdated gen_key()) calls:

api_key = tgk.keys_gen(
    prefix=f"api_{tgk.gen_key(length=8)}_",
    length=32,
    suffix=f"_{tgk.gen_key(length=4)}"
)
# Result = api_<8 random chars>_<32 random>_<4 random>
# Organized and polished identifiers!

This composable design allows you to build complex key structures while maintaining cryptographic security at every level.

Why This Is Better Than secrets

With Python's built-in secrets module:

# pretend we imported secrets and have an alphanumeric
# list of characters

# awkward..
secrets_key = (
    f"api_"
    f"{''.join(secrets.choice(chars) for _ in range(8))}_"
    f"{''.join(secrets.choice(chars) for _ in range(32))}"
    f"_{''.join(secrets.choice(chars) for _ in range(8))}"
)

With tinygenkey

import tinygenkey as tgk

# Much better
tgk_key = tgk.keys_gen(
    prefix=f"api_{tgk.gen_key(length=8)}_",
    length=32,
    suffix=f"_{tgk.gen_key(length=4)}"
)

Cleaner, more readable, easier to maintain.


!!!! WARNING Syntax Migration !!!!

In version 0.2.0, the syntax for gen_key() was replaced by a more powerful and consistent keys_gen(). You may still use gen_key() as usual, but it is deprecated.

On version stable 0.5.0, gen_key() will be deleted, but optional deprecated-supported versions will still be maintained as version >0.5-dep and is NOT preserved in minor updates.

By version 1.0.0, gen_key() will be removed entirely and deprecated-supported versions will stop being maintained.

Save Your Program

If your program cannot be modified and is very important for others, you may ask for a special version that supports gen_key().


GitHub

This project is open-sourced at GitHub: tinygenkey on GitHub

You may further verify the security of the code yourself.


License

This project is protected by the MIT License.


Note from Creator - OOP

We're moving from functional programming to OOP! This means your keys will be made of singular Key objects that store the functions! Look, I know I'm pushing you guys to change syntax every now and then, but it's for the better.

You have more control over your keys in a more uniformed, organized way with the new OOP that comes natively with the flagship versions. What about the functional programming?

It will be removed from the flagship version. At TinyGenKey, 'tiny' is a big part for the products. We want to keep the products as tiny as possible, to fit properly on every* machine!

No worries, because in the first time, I will create a long-term subversion that supports functional programming, called the -nooop version series. For tiny reasons, the nooop versions will not support the new OOP, and any new features.

Sorry for the inconvenience, and keep generating keys!

Cheers, tyydev1, Maintainer/Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinygenkey-0.4.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinygenkey-0.4.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file tinygenkey-0.4.0.tar.gz.

File metadata

  • Download URL: tinygenkey-0.4.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tinygenkey-0.4.0.tar.gz
Algorithm Hash digest
SHA256 31e7001dba2e4da66cd1316d7de6d21ec41a216acbe67f8aa4ef66c5fe04e7b0
MD5 3b0e8acbaae20da446235babb39dbb0d
BLAKE2b-256 f251640042d35f0f68ba3c5ff89eeefb30758f28449cb3e66eab0f69a73f4c02

See more details on using hashes here.

File details

Details for the file tinygenkey-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: tinygenkey-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tinygenkey-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f084296a82b0018129a6116a87822812cc13e339218368780715c99c7ee635a
MD5 74a9470bad3ba0bde43b3884779b3616
BLAKE2b-256 3b2e14bb6d92bdd7f6f644c2ec8ebb4cda1775316391dc0c793899fb5e1cdf44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page