pyobjectify package

Submodules

pyobjectify.pyobjectify module

pyobjectify.pyobjectify.CONVERSIONS = {<InputType.JSON: 1>: [<class 'dict'>, <class 'list'>, <class 'pandas.core.frame.DataFrame'>], <InputType.CSV: 2>: [<class 'list'>], <InputType.TSV: 3>: [<class 'list'>], <InputType.XML: 4>: [<class 'dict'>], <InputType.XLSX: 5>: [<class 'dict'>]}

A dictionary of allowable conversions, where the key is a supported input type, and the value is a list of supported output types.

The end-user does not have to interface with this, but it is provided for more granular operations.

class pyobjectify.pyobjectify.Connectivity(value)

Bases: Enum

An enumeration of the supported file connectivity types:

  • ONLINE_STATIC = The URL points to a static file on the Internet.

  • LOCAL = The URL is a path to a local file.

For example, at the moment, a data stream from the Internet is not supported.

The end-user does not have to interface with this, but it is provided for more granular operations.

LOCAL = 2
ONLINE_STATIC = 1
class pyobjectify.pyobjectify.InputType(value)

Bases: Enum

An enumeration of the input types supported by pyobjectify.

The end-user does not have to interface with this, but it is provided for more granular operations.

CSV = 2
JSON = 1
TSV = 3
XLSX = 5
XML = 4
pyobjectify.pyobjectify.OUTPUT_TYPES = (<class 'list'>, <class 'dict'>, <class 'pandas.core.frame.DataFrame'>)

A set of the output types supported by pyobjectify.

The end-user does not have to interface with this, but it is provided for more granular operations.

class pyobjectify.pyobjectify.Resource(url, connectivity)

Bases: object

The Resource class stores some metadata about the resource to simplify the code.

The end-user does not have to interface with this, but it is provided for more granular operations.

pyobjectify.pyobjectify.convert(resource, conversions)

Attempts to convert the resource data through possible conversions.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:
  • resource (Resource) – he Resource object for the resource.

  • conversions (list) – The list of all possible conversions, filtered if user specified output data type.

Returns:

The first successful conversion from the probable resource type to an output data type.

Return type:

object

Raises:

TypeError – None of the possible conversions were successful.

pyobjectify.pyobjectify.csv_to_list(resource)

Helper function to convert CSV data to a list.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the CSV resource.

Returns:

A list represenation of the CSV resource.

Return type:

list

pyobjectify.pyobjectify.from_url(url, out_type=None)
This is the main interface that the end-user interacts with.

Given a URL, converts the resource data to a parsable Python object.

Parameters:
  • url (str) – A URL to a resource.

  • out_type (class, optional) – The user-specified data type of the output.

Returns:

A parsable Python object representation of the resource.

Return type:

object

Raises:

TypeError – The user-specified data type of the output is not supported.

pyobjectify.pyobjectify.get_conversions(in_types, out_type=None)

Get possible conversions for the probable resource types. If the user specified a preferred output type, filter out any undesirable conversions to consider.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:
  • in_types (list) – A list of calculated possible resource types.

  • out_type (class, optional) – The user-specified data type of the output.

Returns:

A list of (in, out) conversion tuples as described above.

Return type:

list

Raises:

TypeError – There are no possible conversions.

pyobjectify.pyobjectify.get_resource_types(resource)

Get possible resource types of the resource.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the resource.

Returns:

A list of possible resource types of the resource.

Return type:

list

Raises:

TypeError – The resource is of a type that is not supported.

pyobjectify.pyobjectify.json_to_dataframe(resource)

Helper function to convert JSON data to a pandas DataFrame.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the JSON resource.

Returns:

A pandas DataFrame represenation of the JSON resource.

Return type:

pandas.DataFrame

pyobjectify.pyobjectify.json_to_dict(resource)

Helper function to convert JSON data to a dictionary.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the JSON resource.

Returns:

A dictionary represenation of the JSON resource.

Return type:

dict

pyobjectify.pyobjectify.json_to_list(resource)

Helper function to convert JSON data to a list.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the JSON resource.

Returns:

A list represenation of the JSON resource.

Return type:

list

pyobjectify.pyobjectify.retrieve_resource(url, connectivity)

Retrieves the resource at the URL using the connectivity type and stores it in a Resource object.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:
  • url (str) – The URL to a resource.

  • connectivity (Connectivity) – An attribute in the enumeration Connectivity. The calculated connectivity type of the resource.

Returns:

The Resource object for the resource at the URL specified.

Return type:

Resource

Raises:

TypeError – The connectivity type is not supported.

pyobjectify.pyobjectify.tsv_to_list(resource)

Helper function to convert TSV data to a list.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the TSV resource.

Returns:

A list represenation of the TSV resource.

Return type:

list

pyobjectify.pyobjectify.url_to_connectivity(url)

Get the connectivity type of the resource.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

url (str) – The URL to a resource.

Returns:

An attribute in the enumeration Connectivity. The calculated connectivity of the resource type.

Return type:

Connectivity

pyobjectify.pyobjectify.xlsx_to_dict(resource)

Helper function to convert XLSX data to a dictionary.

pyobjectify.pyobjectify.xml_to_dict(resource)

Helper function to convert XML data to a dictionary.

The end-user does not have to interface with this, but it is provided for more granular operations.

Parameters:

resource (Resource) – The Resource object for the XML resource.

Returns:

A dictionary represenation of the XML resource.

Return type:

dict

Module contents