Skip to main content

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+

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!

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

SafeCode-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

SafeCode-0.0.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file SafeCode-0.0.2.tar.gz.

File metadata

  • Download URL: SafeCode-0.0.2.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

Hashes for SafeCode-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a13d5a21ea89ffb17585510ff26eea7a37e7fff33298ac3e42a6f547dd800463
MD5 e47cf5044726a31bd9aed4c0472ea4ed
BLAKE2b-256 6711694b81e7b03da27edf91d8a8b57fbe938cdf7bd65a7d5d3e21b27b021a1d

See more details on using hashes here.

File details

Details for the file SafeCode-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: SafeCode-0.0.2-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

Hashes for SafeCode-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b542bc34d9876ff7f363f5f1c5fed462e59eb87c968bcf0e056b2504e43190ff
MD5 192ad8f67962585d6044d72ea4a650e7
BLAKE2b-256 4d111d5ce0e6c80205aaa4c60d12c6cd5378ce2ff0e8b2bc00113fbfc4b735de

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