Skip to main content

Simple XLSX and CSV to dictionary converter

Project description

sheet2dict

A simple XLSX/CSV to dictionary converter

Installing

To install the package from pip, first run:

python3 -m pip install --no-cache-dir sheet2dict

Required pip packages for sheet2doc: csv, openpyxl

Usage

This library has 2 main features: reading a spreadsheet files and converting them to array of python dictionaries.

- XLSX

Use xlsx_to_dict() method when converting form spreadsheets.
Supported file formats for spreadsheets are: .xlsx,.xlsm,.xltx,.xltm

# Import the library
from sheet2dict import Worksheet

# Create an object
ws = Worksheet()

# Convert 
ws.xlsx_to_dict(path='inventory.xlsx')

# object.headers() returns first row with the data in a spreadsheet 
print(ws.headers())

# object.sheet_items returns converted rows as dictionaries in the array 
print(ws.sheet_items)

You can parse data when worksheet is an object

# Import the library
from sheet2dict import Worksheet

# Example: read spreadsheet as object
path = 'inventory.xlsx'
xlsx_file = open(path, 'rb')
xlsx_file = BytesIO(xlsx_file.read())

# Parse spreadsheet from object
ws = Worksheet()
ws.xlsx_to_dict(path=xlsx_file)
print(ws.headers())

- CSV

Use csv_to_dict() method when converting form csv.
CSV is a format with many variations, better handle encodings and delimiters on user side and not within module itself.

# Import the library
from sheet2dict import Worksheet

# Create an object
ws = Worksheet()

# Read CSV file
csv_file = open('inventory.csv', 'r', encoding='utf-8-sig')

# Convert 
ws.csv_to_dict(csv_file=csv_file, delimiter=';')

# object.headers() returns first row with the data in a spreadsheet 
print(ws.headers())

# object.sheet_items returns converted rows as dictionaries in the array 
print(ws.sheet_items)

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

sheet2dict-0.0.1.tar.gz (2.0 kB view details)

Uploaded Source

Built Distribution

sheet2dict-0.0.1-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file sheet2dict-0.0.1.tar.gz.

File metadata

  • Download URL: sheet2dict-0.0.1.tar.gz
  • Upload date:
  • Size: 2.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for sheet2dict-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1e30a69e368c53306388b7e703c0c11e94b3ace5281631b0cbf30ae96c7f10bd
MD5 a8aa6f7fd8df01054e5f4e0ddf8d382f
BLAKE2b-256 0339956acb5af612ebf7b30be8ceb74af85e31df09279bddd84a21d36e07e5d4

See more details on using hashes here.

File details

Details for the file sheet2dict-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: sheet2dict-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for sheet2dict-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 90c1c548629fe0ffe9b7d2559efda4c37bbdd58a4752573783800846bd1ba048
MD5 2ad8829ed554f112409956d7b82e397a
BLAKE2b-256 a61875568e33c51a26a59de3c07edd1157129cde14dfeea8e550669cef0e8d8b

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