Skip to main content

Load data from spreadsheets easily

Project description

Superspreader 🦠

Superspreader is a little helper library that simplifies working with spreadsheets. It is built on top of openpyxl. OpenPyXL is its only dependency.

Instead of looping over rows and columns manually, the structure of a spreadsheet is described in a class:

from superspreader import fields
from superspreader.sheets import BaseSheet


class AlbumSheet(BaseSheet):
    """
    This class describes a sheet in an Excel document
    """
    
    sheet_name = "Albums" # The sheet is named “albums”
    header_rows = 3 # The sheet has three header rows
    
    # The column labels are in the second row.
    # It is *not* zero based to match the Excel row number
    label_row = 2
    

    # The columns
    artist = fields.CharField(source="Artist", required=True)
    album = fields.CharField(source="Album")
    release_date = fields.DateField(source="Release Date")
    average_review = fields.FloatField(source="Average Review")
    chart_position = fields.IntegerField(source="Chart Position")

Ready? Let’s load an Excel spreadsheet!

if __name__ == "__main__":
    sheet = AlbumSheet("albums.xlsx")
    # Load and parse data from the document
    sheet.load()
    
    print(sheet.has_errors)
    # False
    print(sheet.errors)
    # []
    print(sheet.infos)
    # []
    
    for row_dict in sheet:
        print(row_dict)
        
# {'artist': 'David Bowie', 'album': 'Toy', 'release_date': datetime.date(2022, 1, 7), 'average_review': 4.3, 'chart_position': 5}
# {'artist': 'The Wombats', 'album': 'Fix Yourself, Not The World', 'release_date': datetime.date(2022, 3, 7), 'average_review': 3.9, 'chart_position': 7}
# {'artist': 'Kokoroko', 'album': 'Could We Be More', 'release_date': datetime.date(2022, 8, 1), 'average_review': 4.7, 'chart_position': 30}   

In tests/spreadsheets is a sample spreadsheet that is used for testing. Feel free to fiddle around.

There’s a lot more to say and I’ll update the documentation as I go.

Changelog

0.1.4

  • Adds basic documentation on how to use superspreader

The API is inspired by Django’s model API and ElasticSearch DSL.

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

superspreader-0.1.5.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

superspreader-0.1.5-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file superspreader-0.1.5.tar.gz.

File metadata

  • Download URL: superspreader-0.1.5.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for superspreader-0.1.5.tar.gz
Algorithm Hash digest
SHA256 85d1fb8000195ccdbfaa207c7d252cee19be6cbab7647455f5cb023ff9c2443d
MD5 cc5d1087aaba8c66a0cedb97c8a95432
BLAKE2b-256 9fdc79a22c2a050e160c810e8d78151b76b3ce107715aeb35efd337706bb4a2c

See more details on using hashes here.

File details

Details for the file superspreader-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for superspreader-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 868416e6c84e213e79e4e52855432147cf54e21786bba9e0c82b9b0532bc016c
MD5 fc0078e6e8baceecdb5dd8dede857410
BLAKE2b-256 0e2da01fa4d4928e2755e5f4c44287e90319f97a367e2e4641406032d77ae767

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