Skip to main content

A General Use Python Tookit.

Project description

PyToolkit

Python General tools

Utilities

string_or_list function allows you to interpret a string and return a list. Provides you the option of adding a delimeter using an OR function to return a possible string that you may be expecting possible commond delimeters. Such as: ",|:|\|, ".

Example:

>>> from pytoolkit.utils import string_or_list

>>> test = 'string1,string2 string3|string4'
>>> string_or_list(test)
['string1,string2 string3|string4']
>>> string_or_list(test,delimeters=',| ')
['string1', 'string2', 'string3|string4']
>>> string_or_list(test,delimeters=',| |\|')
['string1', 'string2', 'string3', 'string4']

Maniuplating Dictionaries

Flatten a Dictionary:

import json
from pytoolkit import utilities

sample_dict = {"key1":"value","key2": "value2", "metadata": {"key1": "meta_value1","key2":"meta_value2"}}

# Convert dictionary into a flat dictionary
flat_dict = utilities.flatten_dict(sample_dict)

# Convert dictionary back into a nested ditionary
nest_dict = utilities.nested_dict(flat_dict)

print(f"This is a Flattened Dictionary:\n{json.dumps(flat_dict,indent=1)}")
print(f"This is a Nested Dictionary:\n{json.dumps(nest_dict,indent=1)}")

OUTPUT:

This is a Flattened Dictionary:
{
 "key1": "value",
 "key2": "value2",
 "metadata.key1": "meta_value1",
 "metadata.key2": "meta_value2"
}

This is a Nested Dictionary:
{
 "key1": "value",
 "key2": "value2",
 "metadata": {
  "key1": "meta_value1",
  "key2": "meta_value2"
 }
}

The above is using the default '.' seperator value. There is a mix of commands that can be passed to adjust how the dictionary is expressed. This is useful for expressing data in otherformats that do not allow for nested dictionaries, but need a way to recreate the original formated datastructure.

Nested Dictionary:

TOOD: Create a way to extract a CSV or XCEL file and turn it into a proper dictionary based on the type. Integrate with Splunk

TODO: Add splunk HEC fromatter with proper chunck

TODO: KVSTORE configuration tool.

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

pytoolkit928-0.0.6.tar.gz (49.1 kB view details)

Uploaded Source

Built Distribution

pytoolkit928-0.0.6-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file pytoolkit928-0.0.6.tar.gz.

File metadata

  • Download URL: pytoolkit928-0.0.6.tar.gz
  • Upload date:
  • Size: 49.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for pytoolkit928-0.0.6.tar.gz
Algorithm Hash digest
SHA256 c77eb2aadaf0ae0b1ae4759c135b5cd1d1302e69b3f3fcc5ea5a7e71a6f8c968
MD5 4db690df7123f5fcec60506995dda1bb
BLAKE2b-256 9815136076f20c3c2152b28a8d00ee0fd6fe19b3d7e0abce49910eb6119add5b

See more details on using hashes here.

File details

Details for the file pytoolkit928-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pytoolkit928-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for pytoolkit928-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f1fef2003cb76daa007aa3159e5d3253e99b02bbcee9b15bbad226d14a3efd8f
MD5 b76f5315abacb6cd105924cf4b0c9ca6
BLAKE2b-256 3272ecba59b0127704e693077f5efbe4a2c54670b1310e827be453d0cf23733d

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