Skip to main content

A package for web dev which is base on sqlalchemy and flask.

Project description

Web Develop Kits

Buy Me A Coffee python_requires>=3.6

dbkits

Utils

snake2camel and camel2snake

snake_case and CamelCase Converter, round way to convert style string

from dbkits import Utils
result = Utils.snake2camel('my_model_name')
# result:
# MyModelName
from dbkits import Utils
result = Utils.camel2snake('MyModelName')
# result:
# 'my_model_name'

Slicer

split_list, split_dict and split_number

Tow different ways to split a container or a number.

1. How to use "split_list"

Note: "slice_length" or "container_length" is a control number either one of them is necessary

from webdevkits import Slicer

Slicer.split_list(
    input_data,  # targets, required a list
    slice_length=None,  # setting to make every slice as this number.
    container_length=None,  # setting to be trying to lean on as a container number.
    recurs=True  # dimension reduce as one dimension
)

2. How to use "split_dict"

from webdevkits import Slicer

Slicer.split_dict(
    input_data,  # targets, required a dict
    slice_length=None,  # setting to make every slice as this number.
    container_length=None,  # setting to be trying to lean on as a container number.
)

3. How to use "split_number"

from webdevkits import Slicer

Slicer.split_number(
    number,  # targets, required a number
    slice_length=None,  # setting to make every slice as this number.
    container_length=None,  # setting to be trying to lean on as a container number.
)
Slicer.split_list([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], slice_length=3)
# result:
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
ContainerKnife.split_list([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], slice_length=3)
# result:
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
ContainerKnife.split_list([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], container_length=3)
# result:
# [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]

Demo

from dbkits import Slicer

def demo(**kwargs):
    if 'input_data' in kwargs and isinstance(kwargs['input_data'], list):
        method = getattr(Slicer, 'split_list')
        src = kwargs['input_data']
    elif 'input_data' in kwargs and isinstance(kwargs['input_data'], dict):
        method = getattr(Slicer, 'split_dict')
        src = kwargs['input_data']
    elif 'number' in kwargs and type(kwargs['number']) in [str, int]:
        method = getattr(Slicer, 'split_number')
        src = kwargs['number']
    else:
        raise ValueError(f'Invalid type or error input! {kwargs}')
    results = method(**kwargs)
    print(f'{"":=^90}')
    print(f'Input:\n\t{src}')
    print(f'Results:\n\t{results}')
    print(f'Amount: {len(results)}')
    print(f'{"":-^90}')
    for index, result in enumerate(results):
        print(f'slice {index} | len == {len(result)} | {result}')
    print(f'{"":=^90}')

## ################## Demo a: split list  ################## ##
demo(input_data=[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], slice_length=4)

## ################## Demo b: split dict  ################## ##
input_data = {
    '1': {'name': 'Ajax', 'age': 25},
    '2': {'name': 'Roni', 'age': 29},
    '3': {'name': 'Jeffrey', 'age': 34},
    '4': {'name': 'Josh', 'age': 33},
    '5': {'name': 'Kevin', 'age': 26},
    '6': {'name': 'Jeque', 'age': 23},
    '7': {'name': 'Amy', 'age': 32},
    '8': {'name': 'May', 'age': 49},
    '9': {'name': 'Ronnie', 'age': 22},
}
demo(input_data=input_data, slice_length=2)

## ################## Demo c: split a number ################## ##
demo(number=40, slice_length=7)

1. Model Extractor

Aim to slice cache out models to the python container(list and dict)

Project details


Download files

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

Files for webdevkits, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size webdevkits-0.0.9-py3-none-any.whl (20.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size webdevkits-0.0.9.tar.gz (7.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page