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
.
[!NOTE]
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 toTrue
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for object_case_switcher-0.0.32.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a34b1962e640ea1c7aed8907653584db333bd3f10fcc1999f5b8cb4dd9ec01f |
|
MD5 | d7b718d0c396784391ac4d5d96f1ae90 |
|
BLAKE2b-256 | 9646ba77003260fd8480a827e39b218af9f237baef7042f0a91ea745c12720ae |
Hashes for object_case_switcher-0.0.32-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3109223ef702ad6c352a7a556ed1890c204c636fd177b1566da7a83e909586b1 |
|
MD5 | f9716ea2952af3a3951f044a52b77879 |
|
BLAKE2b-256 | 9bdfa8c4ebe8412e9397959536a293e078aa2f92b9d252d70b73ebbfb3e6a644 |