A simple library for generating unique codes. Suitable if you want to generate unique codes and send them by sms to confirm your phone number, mail or other industry.
Project description
SafeCode
[?] A simple library for generating unique codes. Suitable if you want to generate unique codes and send them by sms to confirm your phone number, mail or other industry.
Installation
Python require 3.6+
install SafeCode libary:
pip install SafeCode
Examples
Configuration setting
from SafeCode import SafeCode as SF
from SafeCode import CodeType
SF.configure(len_code: int = 4, ttl: int = 120, max_size: int = 1024, code_type: CodeType | list[CodeType] = CodeType.default, debug_mode: bool = False)
"""
[!] The configuration is set up once when the whole project is started. [!]
Initialises the cache with the specified parameters.
:param len_code: fixed length of generated code (default 4 digits).
:param ttl: Time to Live (TTL) for each item in the cache in seconds (default is 120 seconds).
:param code_type: Select the type of code to be generated.
:param max_size: Maximum cache size (default is 1024 items).
:param debug_mode: Debug mode for developers (default is False).
"""
Generation of a unique code
from SafeCode import SafeCode as SF
from SafeCode import CodeType
SF.configure(len_code = 6, ttl = 240, code_type = [CodeType.digits, CodeType.strings_uppercase])
unique_code = SF.newCode()
"""
The `newCode()` function returns a unique code.
The code is generated and checked for uniqueness, if this code is already in memory, it is re-generated.
always returns a string
"""
Random code generation
from SafeCode import SafeCode as SF
from SafeCode import CodeType
SF.configure(len_code = 6, ttl = 240, code_type = [CodeType.digits, CodeType.strings_uppercase])
random_code = SF.genCode()
"""
The `genCode()` function returns a random code.
This code is not stored in memory and memory is not used during generation, so it may have already been encountered earlier or later.
always returns a string
"""
Uniqueness check
from SafeCode import SafeCode as SF
from SafeCode import CodeType
SF.configure(len_code = 6, ttl = 240, code_type = [CodeType.digits, CodeType.strings_uppercase])
random_code = SF.genCode()
if SF.checkCode(random_code):
return "The code is available in memory. It's non-unique."
else:
return "The code is not available in memory. It's unique."
"""
The `checkCode()` function checks the code for its presence in memory
When using the `newCode()` function, this procedure of checking the code for uniqueness is not required, only for the `genCode()` function
always returns a bool
"""
Documentation for the library: GitHub WIKI
##the library will be constantly updated and will be better soon!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SafeCode-0.0.1.tar.gz.
File metadata
- Download URL: SafeCode-0.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57d932ca7f516111431d2a424d464fdf5e39d62b18b93a00b9061cd51b0950b4
|
|
| MD5 |
e32065ff20b3c8b792bea97e51389191
|
|
| BLAKE2b-256 |
529e729dcd35e5443ad17978ddc50bf505e5e59355252ecefc17621fd63970e4
|
File details
Details for the file SafeCode-0.0.1-py3-none-any.whl.
File metadata
- Download URL: SafeCode-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ff2ad5375d4f0686eadffed3cd9e92188aca82a754bed27a96bbfed47c0c912
|
|
| MD5 |
279c13bcddf3858121165f96e6ed4723
|
|
| BLAKE2b-256 |
553571daa139fd90c54295d79c5254e32c5210b28f07f21473da15e3bd5507fd
|