Skip to main content

Data Object Mapping

Project description

Jangli

Scope

  • Data Definition
  • Data mapping

Convert json to python object

Convert json or dict to model object.

Supports

  • dict
  • json
  • json dumps
from jangli.json_to_object import json_to_obj

data = '{"password": "123456", "id": 1, "name": "john"}'



class Student:
    def __init__(self):
        self.id = None
        self.name = None
        self.password = None


s = json_to_obj(data, Student)
print(s.name)

Convert json to python object with static variable

Convert json or dict to model object. Class containing static variables

Supports

  • dict
  • json
  • json dumps
from jangli.json_to_object import json_to_obj

data_2 = '{"password": "123456", "id": 1, "name": "john", "school" : "SOHS"}'


class Student:
    school = None

    def __init__(self):
        self.id = None
        self.name = None
        self.password = None


s2 = json_to_obj(data_2, Student)
print(s2.school)

Custom object list

Create list of similar object. Pass a model which you want create a list. It only allows model objects which model passed whle creating list of objects.

from jangli.list_of_object import ListObject


class A:
    def __init__(self, b):
        self.b = b


lt = ListObject(A)
lt.append(A(7))
lt.insert(1, A(8))

print(lt)

Output : [<__main__.A object at 0x00CA3730>, <__main__.A object at 0x00CC6E10>]

Case Change to CamelCase

Converter snack case to camel case.

from jangli.case_type import CamelCase


@CamelCase
class NewClass:

    def __init__(self):
        self.a = 7
        self.b = "hi"
        self.c = True
        self._from = None


new = NewClass()

print(new.__dict__)

String of None to None

Change string of None to None,

EX :

String of None is : x = 'None'

After change : x = None

from jangli.checker.none_checker import NoneChecker

@NoneChecker
class A:

    def __init__(self):
        self.b = 8
        self.c = "None"
        self.d = True


print(A().__dict__)
>>> {'b': 8, 'c': None, 'd': True}

Re-Try Function

If a function failed one or many times, you can retry N no. of times just by passing retry_value = ?.

If retry_value = 1

A function will execute ones, mean while any error any occurring function will through exception.

@Retry(retry_value=1)
def x_fun():
    print("Function is executing ones")

If retry_value = 2

A function will execute twice if first execution fails else only ones.

@Retry(retry_value=2)
def x_fun():
    print("raise exception")
    raise Exception("Try twice")

If retry_value = 0

A function is disabled and could not execute the function.

@Retry(retry_value=0)
def x_fun():
    print("Function is disabled")

MIT License : Copyright (c) 2019 Abhimanyu Haralukallu

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

jangli-1.2.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

jangli-1.2.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file jangli-1.2.1.tar.gz.

File metadata

  • Download URL: jangli-1.2.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.19.1 CPython/3.7.2

File hashes

Hashes for jangli-1.2.1.tar.gz
Algorithm Hash digest
SHA256 a3e4bc3e7f3be327d79f43d744d162a4daf273de91054fe220459917ec444e93
MD5 f4ae6f313152e119f76d0dae1123dd32
BLAKE2b-256 b4d6103258b7713443e453f4077151f1fcb1e868b3d0f18fed1c5880f4e0f9d8

See more details on using hashes here.

File details

Details for the file jangli-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: jangli-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.19.1 CPython/3.7.2

File hashes

Hashes for jangli-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dde3e23d5060087f7061b587a19d7bb0b00c291810c4af281606bdb492e26314
MD5 1f1da344eedc6c7be71dd5df9829a9a5
BLAKE2b-256 73ce5d5ea21d6af0a06ea8cc2c50a32e56e01c975cb405684ae8719460d94ea7

See more details on using hashes here.

Supported by

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