sketchingpy.data_struct

Data structures to support data access (file system, network, browser).

License:

BSD

 1"""Data structures to support data access (file system, network, browser).
 2
 3License:
 4    BSD
 5"""
 6
 7import typing
 8
 9Columns = typing.Iterable[str]
10Records = typing.Iterable[typing.Dict]
11
12
13class DataLayer:
14    """Facade (strategy) for access to data."""
15
16    def get_csv(self, path: str) -> Records:
17        """Load a CSV file as a list of dictionaries.
18
19        Load a CSV file and parse it as a list where each row after the "header row" becomes a
20        dictionary.
21
22        Args:
23            path: The location at which the CSV file can be found.
24
25        Returns:
26            List of dictionary.
27        """
28        raise NotImplementedError('Use implementor.')
29
30    def write_csv(self, records: Records, columns: Columns, path: str):
31        """Write a list of dictionaries as a CSV file.
32
33        Write a CSV file with header row, saving it to local file system or offering it as a
34        download in the browser.
35
36        Args:
37            records: List of dictionaries to be written.
38            columns: Ordered list of columns to include in the CSV file.
39            path: The location at which the file should be written.
40        """
41        raise NotImplementedError('Use implementor.')
42
43    def get_json(self, path: str):
44        """Read a JSON file.
45
46        Read a JSON file either from local file system or the network.
47
48        Args:
49            path: The location at which the JSON file can be found.
50
51        Returns:
52            Loaded JSON content.
53        """
54        raise NotImplementedError('Use implementor.')
55
56    def write_json(self, target, path: str):
57        """Write a JSON file.
58
59        Write a JSON file, saving it to local file system or offering it as a download in the
60        browser.
61
62        Args:
63            target: The value to write as JSON.
64            path: The location at which the file should be written.
65        """
66        raise NotImplementedError('Use implementor.')
67
68    def get_text(self, path: str):
69        """Read a text file.
70
71        Read a text file either from local file system or the network.
72
73        Args:
74            path: The location where the file can be found.
75
76        Returns:
77            Loaded content as a string.
78        """
79        raise NotImplementedError('Use implementor.')
80
81    def write_text(self, target: str, path: str):
82        """Write a text file.
83
84        Write a text file, saving it to local file system or offering it as a download in the
85        browser.
86
87        Args:
88            target: The contents to write.
89            path: The location at which the file should be written.
90        """
91        raise NotImplementedError('Use implementor.')
Columns = typing.Iterable[str]
Records = typing.Iterable[typing.Dict]
class DataLayer:
14class DataLayer:
15    """Facade (strategy) for access to data."""
16
17    def get_csv(self, path: str) -> Records:
18        """Load a CSV file as a list of dictionaries.
19
20        Load a CSV file and parse it as a list where each row after the "header row" becomes a
21        dictionary.
22
23        Args:
24            path: The location at which the CSV file can be found.
25
26        Returns:
27            List of dictionary.
28        """
29        raise NotImplementedError('Use implementor.')
30
31    def write_csv(self, records: Records, columns: Columns, path: str):
32        """Write a list of dictionaries as a CSV file.
33
34        Write a CSV file with header row, saving it to local file system or offering it as a
35        download in the browser.
36
37        Args:
38            records: List of dictionaries to be written.
39            columns: Ordered list of columns to include in the CSV file.
40            path: The location at which the file should be written.
41        """
42        raise NotImplementedError('Use implementor.')
43
44    def get_json(self, path: str):
45        """Read a JSON file.
46
47        Read a JSON file either from local file system or the network.
48
49        Args:
50            path: The location at which the JSON file can be found.
51
52        Returns:
53            Loaded JSON content.
54        """
55        raise NotImplementedError('Use implementor.')
56
57    def write_json(self, target, path: str):
58        """Write a JSON file.
59
60        Write a JSON file, saving it to local file system or offering it as a download in the
61        browser.
62
63        Args:
64            target: The value to write as JSON.
65            path: The location at which the file should be written.
66        """
67        raise NotImplementedError('Use implementor.')
68
69    def get_text(self, path: str):
70        """Read a text file.
71
72        Read a text file either from local file system or the network.
73
74        Args:
75            path: The location where the file can be found.
76
77        Returns:
78            Loaded content as a string.
79        """
80        raise NotImplementedError('Use implementor.')
81
82    def write_text(self, target: str, path: str):
83        """Write a text file.
84
85        Write a text file, saving it to local file system or offering it as a download in the
86        browser.
87
88        Args:
89            target: The contents to write.
90            path: The location at which the file should be written.
91        """
92        raise NotImplementedError('Use implementor.')

Facade (strategy) for access to data.

def get_csv(self, path: str) -> Iterable[Dict]:
17    def get_csv(self, path: str) -> Records:
18        """Load a CSV file as a list of dictionaries.
19
20        Load a CSV file and parse it as a list where each row after the "header row" becomes a
21        dictionary.
22
23        Args:
24            path: The location at which the CSV file can be found.
25
26        Returns:
27            List of dictionary.
28        """
29        raise NotImplementedError('Use implementor.')

Load a CSV file as a list of dictionaries.

Load a CSV file and parse it as a list where each row after the "header row" becomes a dictionary.

Arguments:
  • path: The location at which the CSV file can be found.
Returns:

List of dictionary.

def write_csv(self, records: Iterable[Dict], columns: Iterable[str], path: str):
31    def write_csv(self, records: Records, columns: Columns, path: str):
32        """Write a list of dictionaries as a CSV file.
33
34        Write a CSV file with header row, saving it to local file system or offering it as a
35        download in the browser.
36
37        Args:
38            records: List of dictionaries to be written.
39            columns: Ordered list of columns to include in the CSV file.
40            path: The location at which the file should be written.
41        """
42        raise NotImplementedError('Use implementor.')

Write a list of dictionaries as a CSV file.

Write a CSV file with header row, saving it to local file system or offering it as a download in the browser.

Arguments:
  • records: List of dictionaries to be written.
  • columns: Ordered list of columns to include in the CSV file.
  • path: The location at which the file should be written.
def get_json(self, path: str):
44    def get_json(self, path: str):
45        """Read a JSON file.
46
47        Read a JSON file either from local file system or the network.
48
49        Args:
50            path: The location at which the JSON file can be found.
51
52        Returns:
53            Loaded JSON content.
54        """
55        raise NotImplementedError('Use implementor.')

Read a JSON file.

Read a JSON file either from local file system or the network.

Arguments:
  • path: The location at which the JSON file can be found.
Returns:

Loaded JSON content.

def write_json(self, target, path: str):
57    def write_json(self, target, path: str):
58        """Write a JSON file.
59
60        Write a JSON file, saving it to local file system or offering it as a download in the
61        browser.
62
63        Args:
64            target: The value to write as JSON.
65            path: The location at which the file should be written.
66        """
67        raise NotImplementedError('Use implementor.')

Write a JSON file.

Write a JSON file, saving it to local file system or offering it as a download in the browser.

Arguments:
  • target: The value to write as JSON.
  • path: The location at which the file should be written.
def get_text(self, path: str):
69    def get_text(self, path: str):
70        """Read a text file.
71
72        Read a text file either from local file system or the network.
73
74        Args:
75            path: The location where the file can be found.
76
77        Returns:
78            Loaded content as a string.
79        """
80        raise NotImplementedError('Use implementor.')

Read a text file.

Read a text file either from local file system or the network.

Arguments:
  • path: The location where the file can be found.
Returns:

Loaded content as a string.

def write_text(self, target: str, path: str):
82    def write_text(self, target: str, path: str):
83        """Write a text file.
84
85        Write a text file, saving it to local file system or offering it as a download in the
86        browser.
87
88        Args:
89            target: The contents to write.
90            path: The location at which the file should be written.
91        """
92        raise NotImplementedError('Use implementor.')

Write a text file.

Write a text file, saving it to local file system or offering it as a download in the browser.

Arguments:
  • target: The contents to write.
  • path: The location at which the file should be written.