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+
installing the required library:
pip install xtools-py
install SafeCode libary:
pip install SafeCode
pip install xtools-py 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!
Metadata
Release files for SafeCode 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| SafeCode-0.0.2.tar.gz | 4.5 kB | Without provenance | Details for SafeCode-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| SafeCode-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for SafeCode-0.0.2-py3-none-any.whl |
Total release size: 10.0 kB
Release files / SafeCode-0.0.2.tar.gz
| Download URL | SafeCode-0.0.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a13d5a21ea89ffb17585510ff26eea7a37e7fff33298ac3e42a6f547dd800463
|
|
BLAKE2b-256 checksum How to use checksums |
6711694b81e7b03da27edf91d8a8b57fbe938cdf7bd65a7d5d3e21b27b021a1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.11
|
Release files / SafeCode-0.0.2-py3-none-any.whl
| Download URL | SafeCode-0.0.2-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b542bc34d9876ff7f363f5f1c5fed462e59eb87c968bcf0e056b2504e43190ff
|
|
BLAKE2b-256 checksum How to use checksums |
4d111d5ce0e6c80205aaa4c60d12c6cd5378ce2ff0e8b2bc00113fbfc4b735de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.11
|
Security for SafeCode 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.