Skip to main content

Provides generator to read Kami (god) CSV record as list of string.

Project description

⛩️God Slayer⚔️

Test Test Coverage Maintainability Code Climate technical debt Updates Python versions Twitter URL

Provides generator to read Kami (god) CSV record as list of string.

Context

It's beyond CSV module😱

We often face CSV files like this:

population      
age total number male female
0~4 21303 10867 10436
0 4062 2069 1993
1 4279 2171 2108
2 4285 2152 2133
3 4434 2268 2166
4 4243 2207 2036
5~9 21017 10956 10061
5 4369 2283 2086
6 4345 2213 2132
7 4117 2163 1954
8 4155 2146 2009
9 4031 2151 1880
sum 42320 21823 20497
material: Residents' Culture Department Resident Registration Section      

It's beyond CSV module😱 We just want the population for each age ...

We call such a CSV file Kami CSV.

Features

Let's iterate to read only required row from CSV💡

  • ⚔️ Skips to the row after the header row
  • ⚔️ Skips partition rows
  • ⚔️ Stops iteration bedore footer row

Quickstart

pip install godslayer

Let's resolve above example:

from pathlib import Path

def print_required_row():
    god_slayer_factory = GodSlayerFactory(
        header=["age", "total", "male", "female"],
        partition=[r"^\d*〜\d*$", r"^\d*$", r"^\d*$", r"^\d*$"],
        footer=["sum", r"^\d*$", r"^\d*$", r"^\d*$"],
        encoding="shift_jis_2004",
    )
    god_slayer = god_slayer_factory.create(Path("/path/to/file.csv"))

    for record in god_slayer:
        print(record)
['0', '4062', '2069', '1993']
['1', '4279', '2171', '2108']
['2', '4285', '2152', '2133']
['3', '4434', '2268', '2166']
['4', '4243', '2207', '2036']
['5', '4369', '2283', '2086']
['6', '4345', '2213', '2132']
['7', '4117', '2163', '1954']
['8', '4155', '2146', '2009']
['9', '4031', '2151', '1880']

Note that file will be closeed automatically when variable god_slayer goes out of scope.

Specification

Argument of GodSlayerFactory

property type defalut explanation
header Optional[List[str]] None If present, God Slayer will skip to the row after the header row
partition Optional[List[str]] None If present, God Slayer will skip partition rows
footer Optional[List[str]] None If present, God Slayer will stop iteration bedore footer row
encoding str "utf-8" Encoding to open CSV file

How to match list of string with row

  • List of strings has the same length as row
  • All strings in the list are compared with the string at the same index in the row and must be one of the following:
    • Same string
    • Matched the regular expression

cf. list_string_matcher.py

What is "Kami CSV"?

"Kami CSV" is a CSV that has become a non-normal form by adding headers, footers, intermediate lines, and notes even though the purpose is to export data. The etymology comes from Kami Excel. It's often found in government office or Legacy company service.

Contributing

Check CONTRIBUTING.md

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

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

godslayer-1.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

godslayer-1.1.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file godslayer-1.1.0.tar.gz.

File metadata

  • Download URL: godslayer-1.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for godslayer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1aad456272d8123a8aec819748f94e1b00fd2f5d69abf5c80c5e6ad751761ee7
MD5 1f306bc5ee8524a347f8abdb0ef37743
BLAKE2b-256 8fe08c44d64fc1affdc47ddecf3330d2429bab4c11059107cd81757b8cdccbb3

See more details on using hashes here.

File details

Details for the file godslayer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: godslayer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for godslayer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8849a01d268ff15f1202a31a65ed60fb66a82d4a31f57fe689a34bfc88732e0e
MD5 cdb8a30fa5f74bfd66c9e1c3c4d0718d
BLAKE2b-256 45aff60c8b1297b2738dfdebcfedd2aeec4ab2dd185f6668bd8db89b8b35ea55

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