Skip to main content

Library for convert N-level dictionaries to one-level dictionaries

Project description

general-conversors

general-conversors is a library for convert N-level dictionaries to one-level dictionaries

GitHub license pypi version

Installation

Use the package manager pip to install general-conversors.

pip3 install general-conversors

Usage

To 1-Level dictionary

from conversor.dict import ToOneLevel

source = {
  'error': False,
  'result': {
    'executed': True,
    'payload': 'Hello world',
    'code': 200,
    'source_code_url': 'http://google.com'
  }
}

## replace_underscore as True
conversor = ToOneLevel(source=source, replace_underscore=True)
result = conversor.convert()
print('Result replacing underscore:', result)
# Result replacing underscore: {'error': False, 'result.executed': True, 'result.payload': 'Hello world', 'result.code': 200, 'result.source.code.url': 'http://google.com'}

## replace_underscore as False (Default)
conversor = ToOneLevel(source=source)
result = conversor.convert()
print('Result:', result)
# Result: {'error': False, 'result.executed': True, 'result.payload': 'Hello world', 'result.code': 200, 'result.source_code_url': 'http://google.com'}

To N-level level dictionary

from conversor.dict import ToMultiLevel

source = {
  'error': False,
  'result.executed': True,
  'result.payload': 'Hello world',
  'result.code': 200
}

conversor = ToMultiLevel(source=source)
result = conversor.convert()
print('Result:', result)
# Result: {'error': False, 'result': {'executed': True, 'payload': 'Hello world', 'code': 200}}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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 general-conversors, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size general-conversors-1.0.3.tar.gz (3.0 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