textscribe


Nametextscribe JSON
Version 0.1.7 PyPI version JSON
download
home_page
SummaryEasily Structuring Data
upload_time2023-04-07 18:27:50
maintainer
docs_urlNone
authorHunter Thomas
requires_python
licenseMIT
keywords structure data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CSV, JSON and TXT Reader and Writer Library

This library offers streamlined and efficient methods for reading and writing data to CSV, JSON and TXT files, enabling faster and more convenient data processing.

## Functions

### `write_to_csv(data, filename, labels='None')`

This function takes two lists and adds them to a CSV file line by line. If you choose to add labels, it will add data based on how many label rows there are.

Args:
- `data` (list): A multidimensional list of data for each line.
- `labels` (list): A list of labels for each row (optional).
- `filename` (str): The name of the file.

Returns:
- None

Raises:
- Exception: If the file name is not a .csv file.

### `write_to_txt(data, filename, labels='None', char_separator='None')`

This function takes two lists and adds them to a TXT file line by line. If you choose to add labels, it will add data based on how many label rows there are. If you choose to add a character separator instead of the default `,`, it will add that character in between elements.

Args:
- `data` (list): A multidimensional list of data for each line.
- `labels` (list): A list of labels for each row (optional).
- `filename` (str): The name of the file.
- `char_separator` (str): Character separator (optional).

Returns:
- None

Raises:
- Exception: If the file name is not a .txt file.

## write_to_json(data_list, file_name, labels)

Writes a multi-dimensional list to a JSON file using specified labels.

### Args:
- `data_list` (list): A multi-dimensional list to be written to the JSON file.
- `file_name` (str): The name of the JSON file to be created/overwritten.
- `labels` (list): A list of labels to be used for each list element in the JSON file.

### Raises:
- `Exception`: If `file_name` does not end with '.json'.

### Returns:
None.

---

## Example Usage

```python
from textscribe import scribe

# Example 1: Writing to a CSV file with labels
labels = ['Name', 'Age', 'City']
data = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]
filename = 'example.csv'
scribe.write_to_csv(data, filename, labels=labels)

# Example 2: Writing to a TXT file with labels and a custom separator
labels = ['Name', 'Age', 'City']
data = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]
filename = 'example.txt'
scribe.write_to_txt(data, filename, labels=labels, char_separator='/')

# Example 3: Writing to a JSON file with labels
data_list = [
    ["John", 30],
    ["Jane", 25],
    ["Bob", 40]
]
file_name = "data.json"
labels = ["name", "age"]
scribe.write_to_json(data_list, file_name, labels)
```
### `extract_data_by_label_csv(file_name, label)`

This function extracts data from a CSV file under a specified label.

- `file_name`: The name of the CSV file to read.
- `label`: The label to look for in the CSV file.

### `extract_data_by_label_txt(file_name, label, delimiter=',')`

This function extracts data from a TXT file under a specified label. You can also provide a custom delimiter to separate elements in the TXT file.

- `file_name`: The name of the TXT file to read.
- `label`: The label to look for in the TXT file.
- `delimiter`: The character used to separate elements in the TXT file (optional, default is ',').

## extract_data_by_label_csv

This function extracts data from a CSV file under a specified label.

def extract_data_by_label_csv(file_name, label):


### Args

- file_name (str): The name of the CSV file to read.
- label (str): The label to look for in the CSV file.

### Returns

- list: A list containing all the data under the given label.

### Raises

- ValueError: If the label is not found in the CSV file.
- Exception: If the file name is not a .csv file.

## extract_data_by_label_txt

This function extracts data from a TXT file under a specified label.

def extract_data_by_label_txt(file_name, label, delimiter=','):


### Args

- file_name (str): The name of the TXT file to read.
- label (str): The label to look for in the TXT file.
- delimiter (str): The character used to separate elements in the TXT file. Default is ','.

### Returns

- list: A list containing all the data under the given label.

### Raises

- ValueError: If the label is not found in the TXT file.
- Exception: If the file name is not a .txt file.

## get_json_values(file_name, label)

Searches a JSON file for all occurrences of a specified label, and returns a list of the corresponding values.

### Args:
- `file_name` (str): The name of the JSON file to search.
- `label` (str): The label to search for.

### Raises:
- `Exception`: If `file_name` does not end with '.json'.

### Returns:
A list of the values corresponding to the specified label.


## Example Usage

```python
# Import the necessary modules

from textscribe import scribe

# Example 1: Extracting data from a CSV file
file_name_csv = 'example.csv'
label_csv = 'age'
data_csv = scribe.extract_data_by_label_csv(file_name_csv, label_csv)
print(data_csv)

# Example 2: Extracting data from a TXT file with a custom delimiter
file_name_txt = 'example.txt'
label_txt = 'age'
delimiter_txt = '|'
data_txt = scribe.extract_data_by_label_txt(file_name_txt, label_txt, delimiter_txt)
print(data_txt)

# Example 3: Extracting data from a JSON file
file_name = "data.json"
label = "name"
name_values = get_json_values(file_name, label)
print(name_values)

```

## Github Repo

https://github.com/huntert1004/textscribe






            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "textscribe",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Structure data",
    "author": "Hunter Thomas",
    "author_email": "waidai2027@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/66/bb/abfc2c704dfcc796f070dda21373649c8bfb4642e669b866e9de1e46f0af/textscribe-0.1.7.tar.gz",
    "platform": null,
    "description": "# CSV, JSON and TXT Reader and Writer Library\r\n\r\nThis library offers streamlined and efficient methods for reading and writing data to CSV, JSON and TXT files, enabling faster and more convenient data processing.\r\n\r\n## Functions\r\n\r\n### `write_to_csv(data, filename, labels='None')`\r\n\r\nThis function takes two lists and adds them to a CSV file line by line. If you choose to add labels, it will add data based on how many label rows there are.\r\n\r\nArgs:\r\n- `data` (list): A multidimensional list of data for each line.\r\n- `labels` (list): A list of labels for each row (optional).\r\n- `filename` (str): The name of the file.\r\n\r\nReturns:\r\n- None\r\n\r\nRaises:\r\n- Exception: If the file name is not a .csv file.\r\n\r\n### `write_to_txt(data, filename, labels='None', char_separator='None')`\r\n\r\nThis function takes two lists and adds them to a TXT file line by line. If you choose to add labels, it will add data based on how many label rows there are. If you choose to add a character separator instead of the default `,`, it will add that character in between elements.\r\n\r\nArgs:\r\n- `data` (list): A multidimensional list of data for each line.\r\n- `labels` (list): A list of labels for each row (optional).\r\n- `filename` (str): The name of the file.\r\n- `char_separator` (str): Character separator (optional).\r\n\r\nReturns:\r\n- None\r\n\r\nRaises:\r\n- Exception: If the file name is not a .txt file.\r\n\r\n## write_to_json(data_list, file_name, labels)\r\n\r\nWrites a multi-dimensional list to a JSON file using specified labels.\r\n\r\n### Args:\r\n- `data_list` (list): A multi-dimensional list to be written to the JSON file.\r\n- `file_name` (str): The name of the JSON file to be created/overwritten.\r\n- `labels` (list): A list of labels to be used for each list element in the JSON file.\r\n\r\n### Raises:\r\n- `Exception`: If `file_name` does not end with '.json'.\r\n\r\n### Returns:\r\nNone.\r\n\r\n---\r\n\r\n## Example Usage\r\n\r\n```python\r\nfrom textscribe import scribe\r\n\r\n# Example 1: Writing to a CSV file with labels\r\nlabels = ['Name', 'Age', 'City']\r\ndata = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]\r\nfilename = 'example.csv'\r\nscribe.write_to_csv(data, filename, labels=labels)\r\n\r\n# Example 2: Writing to a TXT file with labels and a custom separator\r\nlabels = ['Name', 'Age', 'City']\r\ndata = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]\r\nfilename = 'example.txt'\r\nscribe.write_to_txt(data, filename, labels=labels, char_separator='/')\r\n\r\n# Example 3: Writing to a JSON file with labels\r\ndata_list = [\r\n    [\"John\", 30],\r\n    [\"Jane\", 25],\r\n    [\"Bob\", 40]\r\n]\r\nfile_name = \"data.json\"\r\nlabels = [\"name\", \"age\"]\r\nscribe.write_to_json(data_list, file_name, labels)\r\n```\r\n### `extract_data_by_label_csv(file_name, label)`\r\n\r\nThis function extracts data from a CSV file under a specified label.\r\n\r\n- `file_name`: The name of the CSV file to read.\r\n- `label`: The label to look for in the CSV file.\r\n\r\n### `extract_data_by_label_txt(file_name, label, delimiter=',')`\r\n\r\nThis function extracts data from a TXT file under a specified label. You can also provide a custom delimiter to separate elements in the TXT file.\r\n\r\n- `file_name`: The name of the TXT file to read.\r\n- `label`: The label to look for in the TXT file.\r\n- `delimiter`: The character used to separate elements in the TXT file (optional, default is ',').\r\n\r\n## extract_data_by_label_csv\r\n\r\nThis function extracts data from a CSV file under a specified label.\r\n\r\ndef extract_data_by_label_csv(file_name, label):\r\n\r\n\r\n### Args\r\n\r\n- file_name (str): The name of the CSV file to read.\r\n- label (str): The label to look for in the CSV file.\r\n\r\n### Returns\r\n\r\n- list: A list containing all the data under the given label.\r\n\r\n### Raises\r\n\r\n- ValueError: If the label is not found in the CSV file.\r\n- Exception: If the file name is not a .csv file.\r\n\r\n## extract_data_by_label_txt\r\n\r\nThis function extracts data from a TXT file under a specified label.\r\n\r\ndef extract_data_by_label_txt(file_name, label, delimiter=','):\r\n\r\n\r\n### Args\r\n\r\n- file_name (str): The name of the TXT file to read.\r\n- label (str): The label to look for in the TXT file.\r\n- delimiter (str): The character used to separate elements in the TXT file. Default is ','.\r\n\r\n### Returns\r\n\r\n- list: A list containing all the data under the given label.\r\n\r\n### Raises\r\n\r\n- ValueError: If the label is not found in the TXT file.\r\n- Exception: If the file name is not a .txt file.\r\n\r\n## get_json_values(file_name, label)\r\n\r\nSearches a JSON file for all occurrences of a specified label, and returns a list of the corresponding values.\r\n\r\n### Args:\r\n- `file_name` (str): The name of the JSON file to search.\r\n- `label` (str): The label to search for.\r\n\r\n### Raises:\r\n- `Exception`: If `file_name` does not end with '.json'.\r\n\r\n### Returns:\r\nA list of the values corresponding to the specified label.\r\n\r\n\r\n## Example Usage\r\n\r\n```python\r\n# Import the necessary modules\r\n\r\nfrom textscribe import scribe\r\n\r\n# Example 1: Extracting data from a CSV file\r\nfile_name_csv = 'example.csv'\r\nlabel_csv = 'age'\r\ndata_csv = scribe.extract_data_by_label_csv(file_name_csv, label_csv)\r\nprint(data_csv)\r\n\r\n# Example 2: Extracting data from a TXT file with a custom delimiter\r\nfile_name_txt = 'example.txt'\r\nlabel_txt = 'age'\r\ndelimiter_txt = '|'\r\ndata_txt = scribe.extract_data_by_label_txt(file_name_txt, label_txt, delimiter_txt)\r\nprint(data_txt)\r\n\r\n# Example 3: Extracting data from a JSON file\r\nfile_name = \"data.json\"\r\nlabel = \"name\"\r\nname_values = get_json_values(file_name, label)\r\nprint(name_values)\r\n\r\n```\r\n\r\n## Github Repo\r\n\r\nhttps://github.com/huntert1004/textscribe\r\n\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Easily Structuring Data",
    "version": "0.1.7",
    "split_keywords": [
        "structure",
        "data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "66bbabfc2c704dfcc796f070dda21373649c8bfb4642e669b866e9de1e46f0af",
                "md5": "13a04bdd7ec7cf62370f61edec83c0c5",
                "sha256": "3f0a4d33fd4949761c6476b33d694969ef27e0da12991c2fe3ded0b7ac9b9a73"
            },
            "downloads": -1,
            "filename": "textscribe-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "13a04bdd7ec7cf62370f61edec83c0c5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5067,
            "upload_time": "2023-04-07T18:27:50",
            "upload_time_iso_8601": "2023-04-07T18:27:50.084437Z",
            "url": "https://files.pythonhosted.org/packages/66/bb/abfc2c704dfcc796f070dda21373649c8bfb4642e669b866e9de1e46f0af/textscribe-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-07 18:27:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "textscribe"
}
        
Elapsed time: 0.05261s