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.2.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

superspreader-0.2.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: superspreader-0.2.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for superspreader-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4494c7d9352419ce203996a1f876b97a6a5b91d3304ac0367d372721f601f5b2
MD5 2110b7e31146dc053815acfdcdf57c0b
BLAKE2b-256 dfb790f459ac1de981a6e8adb1cfa38a4626c7f108356ca18926df88fc66c72a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for superspreader-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3c356c6feddaec7bc61ef49ee121d24b65f03400bf593ae26303db084957f82d
MD5 bb4f6fcca56926f50669cc909c19e260
BLAKE2b-256 fe6b696634e0e0b657256acd34a96a98772bdef1b7ee23f6288d54b9d7ec1fa9

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