Skip to main content

The easiest way to switch case of prop in return of your functions

Project description

CASE SWITCHER

This module provides a very useful feature that will simplify communication between developers of Python RestAPI and other API libraries and frontend developers.

The provided function (transform_structure) makes it possible to develop the main function code on the usual code case, but, called by default, it converts the fields of the object returned by the main function from snake_case to camelCase.

It is better to install this library in your virtual environment

Installing

pip install object_case_switcher

Syntax

@transform_structure()
async def load_data(*args, **kwargs):
    ...

Parameters

  • case_type - Type of transform rule (snakeToCamel, camelToSnake). Defaults to "snakeToCamel"

  • transform_for - Target of executon transform (return, argument). Defaults to "return"

  • arg_index - Index of argument of target function. Defaults to 0

  • arg_name - Name of argument of target function. Defaults to ""

  • _async - Is synchronus or asynchronus target function . Defaults to True

Examples

Simple use

from object_case_switcher import transform_structure

@transform_structure(_async=False)
def some_function():
    return {
        "some_property": 42,
    }

print(some_function())

# >>> '{"someProperty": 42}'

Recursive case

You can return an object with any level of nesting from a function

from object_case_switcher import transform_structure

@transform_structure(_async=False)
def some_function():
    return {
        "some_property": 42,
        "some_other_property": {
            "a": 52,
            "b": [
                {
                    "title_name": "John",
                },
                {
                    "title_name": "Dow",
                },
            ]
        },
    }

print(some_function())

Output

{
    "someProperty": 42,
    "someOtherProperty": {
        "a": 52,
        "b": [
            {"titleName": "John"},
            {"titleName": "Dow"},
        ]
    }
}

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

object_case_switcher-0.0.33.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

object_case_switcher-0.0.33-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file object_case_switcher-0.0.33.tar.gz.

File metadata

  • Download URL: object_case_switcher-0.0.33.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for object_case_switcher-0.0.33.tar.gz
Algorithm Hash digest
SHA256 ff2129d412f61ae7d544d45048948b0eca69e68341dcfccd72ee5b7188319980
MD5 b68a6db29d47f184b19690c09e769b84
BLAKE2b-256 9e9aa2093f46c67d83ae36900b27c389aa417403b39482eef72eeecfe3b26cb7

See more details on using hashes here.

File details

Details for the file object_case_switcher-0.0.33-py3-none-any.whl.

File metadata

File hashes

Hashes for object_case_switcher-0.0.33-py3-none-any.whl
Algorithm Hash digest
SHA256 f2ba40172642adfe6611401992af471458102ed2e7a3217d4b0a250cad9621ea
MD5 17ab1c8da2be4962b153c6d7c9643134
BLAKE2b-256 cfcbc69f74d444771d43ebc2fa1b34f2c89f3f424220dd2d07f94641583b6e3f

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