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.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

jangli-1.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jangli-1.2.0.tar.gz
Algorithm Hash digest
SHA256 11f62a0f41eb749689e383505934d497d6ef07fea1a2c2b0d4abbb48fc8d37e0
MD5 fd2a074cd3acd6eb048da147e6aa28e0
BLAKE2b-256 af411d2a2d1da1d26e820bc51c584b535b29b5d95033eb268c3d012b3c0cbd2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jangli-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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/41.6.0 requests-toolbelt/0.9.1 tqdm/4.19.1 CPython/3.7.2

File hashes

Hashes for jangli-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02bdd2a694fcecaf086ce90581be30af83bb2499b529da9cd53a7461b9337c2e
MD5 f74ce2897e3838621225e29f2260c444
BLAKE2b-256 91724e8a0f6a22518bea715a88e03c33704d83ac5382e7c69320f7a11dce488c

See more details on using hashes here.

Supported by

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