Skip to main content

Dumpo Python Object Serialiser

Project description

Dumpo Python Object Serialiser

Dumpo serialises a Python object recursively to arbitrary levels, optionally in a JSON like format.

Synopsis:

from dumpo import dumpo
print(dumpo(obj))

Keyword arguments:

Argument Description Type Default Value
as_is Data type name or list of them to be shown as is. i.e., f'{obj}' List or string []
as_is_tag String to append to a data item serialised "as is" String "<as_is>"
code_tag String to replace function code String "<code>"
compressed If True compress list to a single line instead of one data item per line Boolean True
debug If True append debug information to each data item, e.g., data type, quotes to use and iterator Boolean False
deep_types Data type names or list of them to be shown even the item is at level maxdepth+1 List or string []
excluded Data item names or list of them to be excluded from serialisation List or string []
excluded_tag String to replace excluded data items. Blank to hide all excluded data items. String "<excluded>"
expand_keys If True serialise structured item keys, else show them as a string. i.e., print(f'{itemKey}') Boolean False
include_all_keys If True include all keys including internal ones (_<name>) and built-in ones (__<name>) excluding __dict__. Boolean False
include_everything Equivalent to include_all_keys=True, include_functions=True, expand_keys=True, with __dict__ included. Boolean False
include_internals If True include internal keys (_<name>) but not built-in ones (__<name>). Boolean False
include_functions If True include object function names (including internal functions if include_all_keys is also True). Boolean False
indent String used for indentation, repeat for the number of levels String "| "
item_quotes Quotation marks for item keys - a 2-character string for open and close respectively; a 1-character string if open and close are the same; blank means no quotation marks for item keys String None
json_like If True serialise in JSON format - implying indent=" " and item_quotes = '"', and False for show_types and show_all_types. Boolean False
maxdepth Maximum levels to serialise Integer 5
quotes Quotation marks for data items - a 2-character string for open and close respectively; a 1-character string if open and close are the same; blank means no quotation marks for data items String ""
show_all_types If True prepend the data type to each data item of all types, e.g., <type>{ ... } Boolean True
show_types If True prepend the data type to each data item except for simple types, e.g., <type>{ ... } Boolean True
too_deep_tag String to replace data items or structures below the maxdepthth level String "<too_deep>"

Dumpo at GitHub

Examples

>>> from dumpo import dumpo
>>> import boto3
>>> ec2 = boto3.client('ec2')
>>> response = ec2.describe_instances()
>>> print(dumpo(response, maxdepth=1))
{
| Reservations: [ <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep>, <too_deep> ],
| ResponseMetadata: {
| | RequestId: <too_deep>,
| | HTTPStatusCode: <too_deep>,
| | HTTPHeaders: <too_deep>,
| | RetryAttempts: <too_deep>
| }
}
>>> print(dumpo(response['Reservations'][0], maxdepth=1))
{
| Groups: [],
| Instances: [ <too_deep> ],
| OwnerId: "999999999999",
| ReservationId: "r-xxxxxxxxxxxxxxxxx"
}
>>> print(dumpo(response['Reservations'][0]['Instances'][0], too_deep_tag='...'))
{
| AmiLaunchIndex: 0,
| ImageId: "ami-xxxxxxxxxxxxxxxxx",
| InstanceId: "i-xxxxxxxxxxxxxxxxx",
| InstanceType: "x9.xxxx",
| KeyName: "xxx",
| LaunchTime: <datetime>yyyy-mm-dd HH:MM:SS+00:00,
| Monitoring: {'State': 'disabled'},
| Placement: {'AvailabilityZone': 'xx-xxxxxx-9x', 'GroupName': '', 'Tenancy': 'default'},
| PrivateDnsName: "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
| PrivateIpAddress: "99.99.99.99",
| ProductCodes: [],
| PublicDnsName: "",
| State: {'Code': 80, 'Name': 'stopped'},
| StateTransitionReason: "User initiated (yyyy-mm-dd HH:MM:SS GMT)",
| SubnetId: "subnet-xxxxxxxx",
| VpcId: "vpc-xxxxxxxx",
| Architecture: "x86_64",
| BlockDeviceMappings: [ {
| | | DeviceName: "/dev/xvda",
| | | Ebs: {'AttachTime': datetime.datetime(yyyy, mm, dd, HH, MM, SS, tzinfo=tzutc()), 'DeleteOnTermination': True, 'Status': 'attached', 'VolumeId': 'vol-xxxxxxxxxxxxxxxxx'}
| | } ],
| ClientToken: "",
| EbsOptimized: False,
| EnaSupport: True,
| Hypervisor: "xen",
| NetworkInterfaces: [ {
| | | Attachment: {'AttachTime': datetime.datetime(yyyy, mm, dd, HH, MM, SS, tzinfo=tzutc()), 'AttachmentId': 'eni-attach-0eb44e06cead04be4', 'DeleteOnTermination': True, 'DeviceIndex': 0, 'Status': 'attached', 'NetworkCardIndex': 0},
| | | Description: "Primary network interface",
| | | Groups: [ {
| | | | | GroupName: "ssh-xxx",
| | | | | GroupId: "sg-xxxxxxxxxxxxxxxxx"
| | | | } ],
| | | Ipv6Addresses: [],
| | | MacAddress: "xx:xx:xx:xx:xx:xx",
| | | NetworkInterfaceId: "eni-xxxxxxxxxxxxxxxxx",
| | | OwnerId: "999999999999",
| | | PrivateDnsName: "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
| | | PrivateIpAddress: "99.99.99.99",
| | | PrivateIpAddresses: [ {
| | | | | Primary: True,
| | | | | PrivateDnsName: "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
| | | | | PrivateIpAddress: "99.99.99.99"
| | | | } ],
| | | SourceDestCheck: True,
| | | Status: "in-use",
| | | SubnetId: "subnet-xxxxxxxx",
| | | VpcId: "vpc-xxxxxxxx",
| | | InterfaceType: "interface"
| | } ],
| RootDeviceName: "/dev/xvda",
| RootDeviceType: "ebs",
| SecurityGroups: [ {
| | | GroupName: "ssh-xxx",
| | | GroupId: "sg-xxxxxxxxxxxxxxxxx"
| | } ],
| SourceDestCheck: True,
| StateReason: {'Code': 'Client.UserInitiatedShutdown', 'Message': 'Client.UserInitiatedShutdown: User initiated shutdown'},
| Tags: [ {
| | | Key: "Name",
| | | Value: "xxx"
| | } ],
| VirtualizationType: "hvm",
| CpuOptions: {'CoreCount': 1, 'ThreadsPerCore': 1},
| CapacityReservationSpecification: {'CapacityReservationPreference': 'open'},
| HibernationOptions: {'Configured': False},
| MetadataOptions: {'State': 'applied', 'HttpTokens': 'optional', 'HttpPutResponseHopLimit': 1, 'HttpEndpoint': 'enabled'},
| EnclaveOptions: {'Enabled': False}
}
>>> print(dumpo(response['Reservations'][0]['Instances'][0], too_deep_tag='...', json_like=True))
{
  "AmiLaunchIndex": 0,
  "ImageId": "ami-xxxxxxxxxxxxxxxxx",
  "InstanceId": "i-xxxxxxxxxxxxxxxxx",
  "InstanceType": "x9.xxxx",
  "KeyName": "xxx",
  "LaunchTime": "yyyy-mm-dd HH:MM:SS+00:00",
  "Monitoring": {
    "State": "disabled"
  },
  "Placement": {
    "AvailabilityZone": "xx-xxxxxx-9x",
    "GroupName": "",
    "Tenancy": "default"
  },
  "PrivateDnsName": "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
  "PrivateIpAddress": "99.99.99.99",
  "ProductCodes": "[]",
  "PublicDnsName": "",
  "State": {
    "Code": 80,
    "Name": "stopped"
  },
  "StateTransitionReason": "User initiated (yyyy-mm-dd HH:MM:SS GMT)",
  "SubnetId": "subnet-xxxxxxxx",
  "VpcId": "vpc-xxxxxxxx",
  "Architecture": "x86_64",
  "BlockDeviceMappings": [ {
      "DeviceName": "/dev/xvda",
      "Ebs": {
        "AttachTime": "yyyy-mm-dd HH:MM:SS+00:00",
        "DeleteOnTermination": "True",
        "Status": "attached",
        "VolumeId": "vol-xxxxxxxxxxxxxxxxx"
      }
    } ],
  "ClientToken": "",
  "EbsOptimized": "False",
  "EnaSupport": "True",
  "Hypervisor": "xen",
  "NetworkInterfaces": [ {
      "Attachment": {
        "AttachTime": "yyyy-mm-dd HH:MM:SS+00:00",
        "AttachmentId": "eni-attach-xxxxxxxxxxxxxxxxx",
        "DeleteOnTermination": "True",
        "DeviceIndex": 0,
        "Status": "attached",
        "NetworkCardIndex": 0
      },
      "Description": "Primary network interface",
      "Groups": [ {
          "GroupName": "ssh-xxx",
          "GroupId": "sg-xxxxxxxxxxxxxxxxx"
        } ],
      "Ipv6Addresses": "[]",
      "MacAddress": "xx:xx:xx:xx:xx:xx",
      "NetworkInterfaceId": "eni-xxxxxxxxxxxxxxxxx",
      "OwnerId": "999999999999",
      "PrivateDnsName": "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
      "PrivateIpAddress": "99.99.99.99",
      "PrivateIpAddresses": [ {
          "Primary": "True",
          "PrivateDnsName": "ip-99-99-99-99.xx-xxxxxx-9.compute.internal",
          "PrivateIpAddress": "99.99.99.99"
        } ],
      "SourceDestCheck": "True",
      "Status": "in-use",
      "SubnetId": "subnet-xxxxxxxx",
      "VpcId": "vpc-xxxxxxxx",
      "InterfaceType": "interface"
    } ],
  "RootDeviceName": "/dev/xvda",
  "RootDeviceType": "ebs",
  "SecurityGroups": [ {
      "GroupName": "ssh-xxx",
      "GroupId": "sg-xxxxxxxxxxxxxxxxx"
    } ],
  "SourceDestCheck": "True",
  "StateReason": {
    "Code": "Client.UserInitiatedShutdown",
    "Message": "Client.UserInitiatedShutdown: User initiated shutdown"
  },
  "Tags": [ {
      "Key": "Name",
      "Value": "xxx"
    } ],
  "VirtualizationType": "hvm",
  "CpuOptions": {
    "CoreCount": 1,
    "ThreadsPerCore": 1
  },
  "CapacityReservationSpecification": {
    "CapacityReservationPreference": "open"
  },
  "HibernationOptions": {
    "Configured": "False"
  },
  "MetadataOptions": {
    "State": "applied",
    "HttpTokens": "optional",
    "HttpPutResponseHopLimit": 1,
    "HttpEndpoint": "enabled"
  },
  "EnclaveOptions": {
    "Enabled": "False"
  }
}

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

dumpo-0.0.8.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

dumpo-0.0.8-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file dumpo-0.0.8.tar.gz.

File metadata

  • Download URL: dumpo-0.0.8.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for dumpo-0.0.8.tar.gz
Algorithm Hash digest
SHA256 e7a49125b64ade9f44f1c3c7bbdfe3a02df8a5cda503761be223f9ff4439a881
MD5 7f2eca3e55f00db84351089afe62b04b
BLAKE2b-256 520983c38f0b12b979dd21cb166d708684b4c9dce655ab502fd52d53c34b06f3

See more details on using hashes here.

File details

Details for the file dumpo-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: dumpo-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.6.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for dumpo-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dee60d685af05d61402e6bd3295bc9a71edb94b4450d5227aafebdb3ee0e0704
MD5 90a669bdef7ac6560eed8f50abbb9463
BLAKE2b-256 6902a0e3e5a0dcd77338c3a675b50fab8b4e9ddb076170a793f916f242d91c9d

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