rowsift 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rowsift-0.1.1/.github/workflows/release.yml +53 -0
- rowsift-0.1.1/.github/workflows/verify.yml +58 -0
- rowsift-0.1.1/.gitignore +21 -0
- rowsift-0.1.1/CONTRIBUTING.md +58 -0
- rowsift-0.1.1/LICENSE +177 -0
- rowsift-0.1.1/NOTICE +4 -0
- rowsift-0.1.1/PKG-INFO +148 -0
- rowsift-0.1.1/README.md +113 -0
- rowsift-0.1.1/SECURITY.md +25 -0
- rowsift-0.1.1/docs/cleaning.md +145 -0
- rowsift-0.1.1/docs/codes.md +160 -0
- rowsift-0.1.1/docs/mapping.md +111 -0
- rowsift-0.1.1/docs/profiling.md +82 -0
- rowsift-0.1.1/docs/quick-start.md +89 -0
- rowsift-0.1.1/docs/reading.md +77 -0
- rowsift-0.1.1/docs/sifting.md +77 -0
- rowsift-0.1.1/justfile +73 -0
- rowsift-0.1.1/pyproject.toml +79 -0
- rowsift-0.1.1/scripts/check_release_tag.py +39 -0
- rowsift-0.1.1/scripts/check_text.py +44 -0
- rowsift-0.1.1/scripts/generate_reading_fixtures.py +662 -0
- rowsift-0.1.1/scripts/smoke_install.py +99 -0
- rowsift-0.1.1/src/rowsift/__init__.py +98 -0
- rowsift-0.1.1/src/rowsift/clean/__init__.py +44 -0
- rowsift-0.1.1/src/rowsift/clean/_common.py +30 -0
- rowsift-0.1.1/src/rowsift/clean/_dates.py +283 -0
- rowsift-0.1.1/src/rowsift/clean/_dispatch.py +49 -0
- rowsift-0.1.1/src/rowsift/clean/_identifiers.py +161 -0
- rowsift-0.1.1/src/rowsift/clean/_mask.py +117 -0
- rowsift-0.1.1/src/rowsift/clean/_numbers.py +137 -0
- rowsift-0.1.1/src/rowsift/clean/_options.py +75 -0
- rowsift-0.1.1/src/rowsift/clean/_phone.py +202 -0
- rowsift-0.1.1/src/rowsift/clean/_text.py +102 -0
- rowsift-0.1.1/src/rowsift/errors.py +124 -0
- rowsift-0.1.1/src/rowsift/map/__init__.py +24 -0
- rowsift-0.1.1/src/rowsift/map/_fields.py +75 -0
- rowsift-0.1.1/src/rowsift/map/_saved.py +132 -0
- rowsift-0.1.1/src/rowsift/map/_score.py +178 -0
- rowsift-0.1.1/src/rowsift/map/_suggest.py +168 -0
- rowsift-0.1.1/src/rowsift/map/_types.py +169 -0
- rowsift-0.1.1/src/rowsift/profile/__init__.py +17 -0
- rowsift-0.1.1/src/rowsift/profile/_headers.py +44 -0
- rowsift-0.1.1/src/rowsift/profile/_kinds.py +165 -0
- rowsift-0.1.1/src/rowsift/profile/_options.py +69 -0
- rowsift-0.1.1/src/rowsift/profile/_profile.py +119 -0
- rowsift-0.1.1/src/rowsift/profile/_structure.py +157 -0
- rowsift-0.1.1/src/rowsift/profile/_types.py +96 -0
- rowsift-0.1.1/src/rowsift/py.typed +0 -0
- rowsift-0.1.1/src/rowsift/read/__init__.py +6 -0
- rowsift-0.1.1/src/rowsift/read/_cells.py +93 -0
- rowsift-0.1.1/src/rowsift/read/_detect.py +124 -0
- rowsift-0.1.1/src/rowsift/read/_grid.py +128 -0
- rowsift-0.1.1/src/rowsift/read/_limits.py +44 -0
- rowsift-0.1.1/src/rowsift/read/_read.py +99 -0
- rowsift-0.1.1/src/rowsift/read/_text.py +250 -0
- rowsift-0.1.1/src/rowsift/read/_workbook.py +36 -0
- rowsift-0.1.1/src/rowsift/read/_xls.py +115 -0
- rowsift-0.1.1/src/rowsift/read/_xlsx.py +121 -0
- rowsift-0.1.1/src/rowsift/sift/__init__.py +19 -0
- rowsift-0.1.1/src/rowsift/sift/_sift.py +165 -0
- rowsift-0.1.1/src/rowsift/sift/_types.py +119 -0
- rowsift-0.1.1/src/rowsift/types.py +378 -0
- rowsift-0.1.1/tests/__init__.py +0 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/comma_in_free_text_of_semicolon_file.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/comma_in_free_text_of_semicolon_file.expected.json +29 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/crlf_and_cr_line_ends.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/crlf_and_cr_line_ends.expected.json +30 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/pipe.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/pipe.expected.json +29 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/quoted_newline_and_quote.csv +4 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/quoted_newline_and_quote.expected.json +26 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/semicolon_quoted_commas.csv +2 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/semicolon_quoted_commas.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/single_column.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/single_column.expected.json +23 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/unterminated_quote.csv +4 -0
- rowsift-0.1.1/tests/fixtures/reading/delimiter/unterminated_quote.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/cp1252.csv +2 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/cp1252.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/latin1_undefined_in_cp1252.csv +2 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/latin1_undefined_in_cp1252.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf16be_no_mark.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf16be_no_mark.txt +0 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf16le_tab.expected.json +24 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf16le_tab.txt +0 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf8_bom.csv +2 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf8_bom.expected.json +24 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf8_plain.csv +2 -0
- rowsift-0.1.1/tests/fixtures/reading/encoding/utf8_plain.expected.json +22 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/empty_file.csv +0 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/empty_file.expected.json +13 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/ragged_rows.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/ragged_rows.expected.json +32 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/trailing_empty_columns.csv +3 -0
- rowsift-0.1.1/tests/fixtures/reading/grid/trailing_empty_columns.expected.json +28 -0
- rowsift-0.1.1/tests/fixtures/reading/limits/declares_two_gigabytes.expected.json +6 -0
- rowsift-0.1.1/tests/fixtures/reading/limits/declares_two_gigabytes.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/merged/area_clipped_to_the_data.expected.json +28 -0
- rowsift-0.1.1/tests/fixtures/reading/merged/area_clipped_to_the_data.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/merged/vertical_group_label.expected.json +38 -0
- rowsift-0.1.1/tests/fixtures/reading/merged/vertical_group_label.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/all_sheets_empty.expected.json +16 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/all_sheets_empty.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/choose_by_index.expected.json +26 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/choose_by_index.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/choose_by_name.expected.json +26 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/choose_by_name.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/empty_first_sheet.expected.json +23 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/empty_first_sheet.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/empty_first_sheet_legacy.expected.json +23 -0
- rowsift-0.1.1/tests/fixtures/reading/sheets/empty_first_sheet_legacy.xls +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/duration_legacy.expected.json +28 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/duration_legacy.xls +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/huge_dimension_small_data.expected.json +24 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/huge_dimension_small_data.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/phone_as_number.expected.json +25 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/phone_as_number.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/types.expected.json +43 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/types.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/types_legacy.expected.json +66 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/types_legacy.xls +0 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/wrong_dimension.expected.json +28 -0
- rowsift-0.1.1/tests/fixtures/reading/workbook_cells/wrong_dimension.xlsx +0 -0
- rowsift-0.1.1/tests/fixtures/sifting/category.csv +6 -0
- rowsift-0.1.1/tests/fixtures/sifting/category.expected.json +103 -0
- rowsift-0.1.1/tests/fixtures/sifting/closing_total_line.csv +8 -0
- rowsift-0.1.1/tests/fixtures/sifting/closing_total_line.expected.json +66 -0
- rowsift-0.1.1/tests/fixtures/sifting/contacts.csv +10 -0
- rowsift-0.1.1/tests/fixtures/sifting/contacts.expected.json +192 -0
- rowsift-0.1.1/tests/fixtures/sifting/cp1252_landline.csv +3 -0
- rowsift-0.1.1/tests/fixtures/sifting/cp1252_landline.expected.json +68 -0
- rowsift-0.1.1/tests/fixtures/sifting/finance.csv +6 -0
- rowsift-0.1.1/tests/fixtures/sifting/finance.expected.json +157 -0
- rowsift-0.1.1/tests/fixtures/sifting/no_header.csv +3 -0
- rowsift-0.1.1/tests/fixtures/sifting/no_header.expected.json +91 -0
- rowsift-0.1.1/tests/fixtures/sifting/scientific_notation_phone.csv +5 -0
- rowsift-0.1.1/tests/fixtures/sifting/scientific_notation_phone.expected.json +75 -0
- rowsift-0.1.1/tests/map_helpers.py +40 -0
- rowsift-0.1.1/tests/profile_helpers.py +22 -0
- rowsift-0.1.1/tests/read_helpers.py +89 -0
- rowsift-0.1.1/tests/test_clean_dates.py +320 -0
- rowsift-0.1.1/tests/test_clean_dispatch.py +94 -0
- rowsift-0.1.1/tests/test_clean_identifiers.py +189 -0
- rowsift-0.1.1/tests/test_clean_mask.py +88 -0
- rowsift-0.1.1/tests/test_clean_numbers.py +129 -0
- rowsift-0.1.1/tests/test_clean_phone.py +269 -0
- rowsift-0.1.1/tests/test_clean_text.py +170 -0
- rowsift-0.1.1/tests/test_dependency_direction.py +120 -0
- rowsift-0.1.1/tests/test_docs.py +123 -0
- rowsift-0.1.1/tests/test_errors.py +121 -0
- rowsift-0.1.1/tests/test_map_assign.py +142 -0
- rowsift-0.1.1/tests/test_map_fields.py +69 -0
- rowsift-0.1.1/tests/test_map_fingerprint.py +34 -0
- rowsift-0.1.1/tests/test_map_public.py +49 -0
- rowsift-0.1.1/tests/test_map_saved.py +146 -0
- rowsift-0.1.1/tests/test_map_suggest.py +209 -0
- rowsift-0.1.1/tests/test_package.py +7 -0
- rowsift-0.1.1/tests/test_profile_headers.py +37 -0
- rowsift-0.1.1/tests/test_profile_kinds.py +142 -0
- rowsift-0.1.1/tests/test_profile_public.py +26 -0
- rowsift-0.1.1/tests/test_profile_stats.py +235 -0
- rowsift-0.1.1/tests/test_profile_structure.py +206 -0
- rowsift-0.1.1/tests/test_public_api.py +110 -0
- rowsift-0.1.1/tests/test_read_cells.py +50 -0
- rowsift-0.1.1/tests/test_read_detect.py +70 -0
- rowsift-0.1.1/tests/test_read_encrypted.py +67 -0
- rowsift-0.1.1/tests/test_read_fixtures.py +54 -0
- rowsift-0.1.1/tests/test_read_grid.py +83 -0
- rowsift-0.1.1/tests/test_read_limits.py +136 -0
- rowsift-0.1.1/tests/test_read_text.py +114 -0
- rowsift-0.1.1/tests/test_read_workbooks.py +256 -0
- rowsift-0.1.1/tests/test_release_tag.py +53 -0
- rowsift-0.1.1/tests/test_sift.py +243 -0
- rowsift-0.1.1/tests/test_sift_corpus.py +120 -0
- rowsift-0.1.1/tests/test_types.py +266 -0
- rowsift-0.1.1/tests/test_types_reason.py +44 -0
- rowsift-0.1.1/uv.lock +616 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
# A release is a tag that starts with v. Nothing else triggers this workflow.
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
tags:
|
|
7
|
+
- "v*"
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: build the distribution
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
timeout-minutes: 15
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0 # the next step needs the history of main
|
|
21
|
+
- uses: astral-sh/setup-uv@v5
|
|
22
|
+
- uses: extractions/setup-just@v2
|
|
23
|
+
- name: The tagged commit must be on main
|
|
24
|
+
run: |
|
|
25
|
+
git fetch origin main
|
|
26
|
+
git merge-base --is-ancestor "$GITHUB_SHA" origin/main
|
|
27
|
+
- name: The tag must match the package version
|
|
28
|
+
run: python3 scripts/check_release_tag.py "$GITHUB_REF_NAME" pyproject.toml
|
|
29
|
+
- run: uv sync --all-extras
|
|
30
|
+
- run: just verify
|
|
31
|
+
- run: just smoke-core
|
|
32
|
+
- run: just smoke-extras
|
|
33
|
+
- uses: actions/upload-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
37
|
+
if-no-files-found: error
|
|
38
|
+
|
|
39
|
+
publish:
|
|
40
|
+
name: publish to PyPI
|
|
41
|
+
needs: build
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
timeout-minutes: 10
|
|
44
|
+
environment: pypi
|
|
45
|
+
permissions:
|
|
46
|
+
# Trusted publishing: PyPI trusts this workflow's identity, no token is stored.
|
|
47
|
+
id-token: write
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/download-artifact@v4
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
- uses: pypa/gh-action-pypi-publish@v1.14.3
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: verify
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: verify-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
verify:
|
|
17
|
+
name: just verify (Python ${{ matrix.python }})
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
timeout-minutes: 15
|
|
20
|
+
strategy:
|
|
21
|
+
fail-fast: false
|
|
22
|
+
matrix:
|
|
23
|
+
python: ["3.11", "3.12", "3.13", "3.14"]
|
|
24
|
+
env:
|
|
25
|
+
UV_PYTHON: ${{ matrix.python }}
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
- uses: astral-sh/setup-uv@v5
|
|
29
|
+
with:
|
|
30
|
+
enable-cache: true
|
|
31
|
+
- uses: extractions/setup-just@v2
|
|
32
|
+
# Every extra and the dev tools: the test suite runs against the real
|
|
33
|
+
# workbook readers and the real phone library. `just verify` also runs
|
|
34
|
+
# the suite again on the core alone (`just test-core`), and the install
|
|
35
|
+
# job below checks the built wheel.
|
|
36
|
+
- run: uv sync --all-extras
|
|
37
|
+
- run: just verify
|
|
38
|
+
|
|
39
|
+
install:
|
|
40
|
+
name: install the wheel (Python ${{ matrix.python }})
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
timeout-minutes: 15
|
|
43
|
+
strategy:
|
|
44
|
+
fail-fast: false
|
|
45
|
+
matrix:
|
|
46
|
+
python: ["3.11", "3.12", "3.13", "3.14"]
|
|
47
|
+
env:
|
|
48
|
+
UV_PYTHON: ${{ matrix.python }}
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
- uses: astral-sh/setup-uv@v5
|
|
52
|
+
with:
|
|
53
|
+
enable-cache: true
|
|
54
|
+
- uses: extractions/setup-just@v2
|
|
55
|
+
- name: The core alone, with no optional dependency
|
|
56
|
+
run: just smoke-core
|
|
57
|
+
- name: Every extra installed
|
|
58
|
+
run: just smoke-extras
|
rowsift-0.1.1/.gitignore
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
.venv-core/
|
|
5
|
+
.pytest_cache/
|
|
6
|
+
.mypy_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
.coverage
|
|
9
|
+
htmlcov/
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
|
|
14
|
+
# Secrets and local state
|
|
15
|
+
.env
|
|
16
|
+
.env.*
|
|
17
|
+
!.env.example
|
|
18
|
+
|
|
19
|
+
.DS_Store
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
This guide explains how to report a problem, suggest a change and send code.
|
|
4
|
+
|
|
5
|
+
## Report a problem
|
|
6
|
+
|
|
7
|
+
Open an [issue](https://github.com/msantino/rowsift/issues) with:
|
|
8
|
+
|
|
9
|
+
- what you did, what you expected and what happened;
|
|
10
|
+
- the rowsift version and the Python version;
|
|
11
|
+
- the smallest file that reproduces it.
|
|
12
|
+
|
|
13
|
+
**Never attach real data.** A file that reproduces a reading problem almost never needs real names, phone numbers or tax ids. Replace them with invented values that keep the same shape: the same number of digits, the same separators, the same encoding. Tax ids used in examples must be invented and must not belong to anyone.
|
|
14
|
+
|
|
15
|
+
A vulnerability is reported in private, as described in [SECURITY.md](SECURITY.md), never in a public issue.
|
|
16
|
+
|
|
17
|
+
## Suggest a change
|
|
18
|
+
|
|
19
|
+
Open an issue that describes the file or the value you could not handle, before describing the solution. A sample that fails is the most useful thing a suggestion can carry.
|
|
20
|
+
|
|
21
|
+
## Send code
|
|
22
|
+
|
|
23
|
+
1. Open or comment on an issue before starting anything larger than a small fix.
|
|
24
|
+
2. Fork the repository, branch from `main` and open a pull request.
|
|
25
|
+
3. A pull request does one thing and says why.
|
|
26
|
+
4. Commits follow [Conventional Commits](https://www.conventionalcommits.org/) (`fix(read): keep the BOM out of the first header`). Pull requests are squashed on merge.
|
|
27
|
+
|
|
28
|
+
### Rules
|
|
29
|
+
|
|
30
|
+
- **No silent guesses.** A value that cannot be normalized with certainty is returned with a reason, not corrected.
|
|
31
|
+
- **No user-facing text.** Reasons are codes with data. Messages belong to the application.
|
|
32
|
+
- **No framework and no storage.** The library takes bytes and values and returns values.
|
|
33
|
+
- **Every behavior has a test, and every file format quirk has a fixture.** Fixtures are synthetic: they are written for the test and contain no real person's data.
|
|
34
|
+
- **Typed public API.** `mypy --strict` passes on `src` and `tests`.
|
|
35
|
+
- **Plain sentences.** Do not use the em dash character in any file.
|
|
36
|
+
|
|
37
|
+
### Run it locally
|
|
38
|
+
|
|
39
|
+
You need [uv](https://docs.astral.sh/uv/) and [just](https://just.systems/).
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
just setup
|
|
43
|
+
just verify # lint, type check, tests, text check and build
|
|
44
|
+
just fmt # apply the formatter and the safe lint fixes
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A pull request is merged only with `just verify` passing. CI runs the same recipe on every supported Python version.
|
|
48
|
+
|
|
49
|
+
## License of contributions
|
|
50
|
+
|
|
51
|
+
rowsift is distributed under the [Apache License 2.0](LICENSE). By sending a contribution you state that:
|
|
52
|
+
|
|
53
|
+
1. the contribution is yours, or you have the right to send it ([Developer Certificate of Origin 1.1](https://developercertificate.org/)). Sign your commits with `git commit -s`;
|
|
54
|
+
2. you license it under the Apache License 2.0, as section 5 of the license describes.
|
|
55
|
+
|
|
56
|
+
## Conduct
|
|
57
|
+
|
|
58
|
+
Be respectful. Technical disagreement is welcome, personal attacks are not. The maintainer may moderate comments and close discussions that leave that line.
|
rowsift-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
rowsift-0.1.1/NOTICE
ADDED
rowsift-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rowsift
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Read spreadsheets written by people: find the table, infer what each column holds, clean the values and map them to the fields you declare.
|
|
5
|
+
Project-URL: Repository, https://github.com/msantino/rowsift
|
|
6
|
+
Project-URL: Issues, https://github.com/msantino/rowsift/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/msantino/rowsift/tree/main/docs
|
|
8
|
+
Author: Marcelo Santino
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: column-mapping,csv,data-cleaning,excel,import,spreadsheet
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: openpyxl<4,>=3.1; extra == 'all'
|
|
27
|
+
Requires-Dist: phonenumbers<10,>=8.13; extra == 'all'
|
|
28
|
+
Requires-Dist: xlrd<3,>=2.0.1; extra == 'all'
|
|
29
|
+
Provides-Extra: excel
|
|
30
|
+
Requires-Dist: openpyxl<4,>=3.1; extra == 'excel'
|
|
31
|
+
Requires-Dist: xlrd<3,>=2.0.1; extra == 'excel'
|
|
32
|
+
Provides-Extra: phone
|
|
33
|
+
Requires-Dist: phonenumbers<10,>=8.13; extra == 'phone'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# rowsift
|
|
37
|
+
|
|
38
|
+
rowsift reads spreadsheets written by people and turns them into typed, clean rows mapped to the fields your application declares.
|
|
39
|
+
|
|
40
|
+
A file exported by a person is rarely a clean table. The header sits on the fourth row under a title and a blank line. The encoding is whatever the spreadsheet program chose. Phone numbers come in five formats, dates have no year, and the column you need is called `Cel 2`. rowsift handles that part of an import, on the server, and reports every decision it made so the application can show it to the person who sent the file.
|
|
41
|
+
|
|
42
|
+
## What it does
|
|
43
|
+
|
|
44
|
+
The work is split into four steps. Each one can be used on its own.
|
|
45
|
+
|
|
46
|
+
| Step | Input | Output |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| **Read** | bytes of a CSV, XLSX or XLS file | a grid of text cells, plus how it was read: format, encoding, delimiter, sheet |
|
|
49
|
+
| **Profile** | the grid | where the header is, which rows are data, and what each column holds: text, number, money, date, day and month, phone, e-mail, tax id, postal code, or a small set of repeated values |
|
|
50
|
+
| **Clean** | one value and the kind it should be | the normalized value, or the reason it could not be normalized |
|
|
51
|
+
| **Map** | the profile and the fields you declare | a suggested column for each field, with a confidence level and the reason for it |
|
|
52
|
+
|
|
53
|
+
Applying a mapping to a file gives typed rows, the rows that were rejected with the reason for each, and counts of what was changed.
|
|
54
|
+
|
|
55
|
+
## What it does not do
|
|
56
|
+
|
|
57
|
+
- It does not store anything. Models, jobs, uploads and screens belong to the application.
|
|
58
|
+
- It does not guess silently. A phone number cut short by an export is reported as cut short, never completed.
|
|
59
|
+
- It does not write user-facing text. Reasons are returned as codes with their data, so the application writes the message in its own language and tone.
|
|
60
|
+
- It does not depend on a web framework.
|
|
61
|
+
|
|
62
|
+
## Formats and conventions
|
|
63
|
+
|
|
64
|
+
Brazilian conventions are supported from the first version, because that is where the library started: day-first dates, decimal comma, CPF and CNPJ check digits, CEP, and mobile numbers written with or without the ninth digit. Region-specific behavior is selected through options, and the defaults are documented with each function.
|
|
65
|
+
|
|
66
|
+
## Example
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import rowsift
|
|
70
|
+
|
|
71
|
+
data = (
|
|
72
|
+
"Cadastro de clientes\n"
|
|
73
|
+
"\n"
|
|
74
|
+
"Nome;Celular;Nascimento\n"
|
|
75
|
+
"ana souza;(11) 91234-5678;03/04/1990\n"
|
|
76
|
+
"bruno lima;(11) 9123;15/08/1985\n"
|
|
77
|
+
).encode("utf-8")
|
|
78
|
+
|
|
79
|
+
table = rowsift.read(data)
|
|
80
|
+
profile = rowsift.profile(table)
|
|
81
|
+
|
|
82
|
+
fields = [
|
|
83
|
+
rowsift.Field("name", rowsift.Kind.NAME, required=True, aliases=("Nome",)),
|
|
84
|
+
rowsift.Field("phone", rowsift.Kind.PHONE, aliases=("Celular",)),
|
|
85
|
+
rowsift.Field("birthday", rowsift.Kind.DATE, aliases=("Nascimento",)),
|
|
86
|
+
]
|
|
87
|
+
mapping = rowsift.suggest(profile, fields)
|
|
88
|
+
result = rowsift.sift(table, profile, mapping, fields)
|
|
89
|
+
|
|
90
|
+
assert result.summary.kept == 2
|
|
91
|
+
assert result.rows[0].values["name"] == "Ana Souza"
|
|
92
|
+
assert result.rows[0].values["phone"] == "+5511912345678"
|
|
93
|
+
# A phone number cut short is reported, not completed.
|
|
94
|
+
assert result.rows[1].values["phone"] is None
|
|
95
|
+
assert result.rows[1].issues["phone"].code == "too_short"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The header was found under a title and a blank line, each column was matched to a field, and the second phone number came back with a reason code instead of a guess. The [quick start](https://github.com/msantino/rowsift/blob/main/docs/quick-start.md) walks through the same file step by step.
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
- [Quick start](https://github.com/msantino/rowsift/blob/main/docs/quick-start.md)
|
|
103
|
+
- [Reading](https://github.com/msantino/rowsift/blob/main/docs/reading.md): formats, encodings, limits, errors
|
|
104
|
+
- [Profiling](https://github.com/msantino/rowsift/blob/main/docs/profiling.md): the header, skipped rows, kinds
|
|
105
|
+
- [Cleaning](https://github.com/msantino/rowsift/blob/main/docs/cleaning.md): one function per kind, options, masking
|
|
106
|
+
- [Mapping](https://github.com/msantino/rowsift/blob/main/docs/mapping.md): suggestions, confidence, saved mappings
|
|
107
|
+
- [Sifting](https://github.com/msantino/rowsift/blob/main/docs/sifting.md): rows, rejections, counts
|
|
108
|
+
- [Codes](https://github.com/msantino/rowsift/blob/main/docs/codes.md): every code and what it means
|
|
109
|
+
|
|
110
|
+
## Status
|
|
111
|
+
|
|
112
|
+
Early development, version `0.1.1`. The API can still change between minor versions. Before `1.0.0`, a breaking change raises the minor version. Removing or renaming a public name or a code is a breaking change, and adding a code is a minor change.
|
|
113
|
+
|
|
114
|
+
| Step | State |
|
|
115
|
+
|---|---|
|
|
116
|
+
| Read | available: `rowsift.read(...)` turns CSV, XLSX and XLS bytes into a grid of text cells and a report, under explicit limits. XLSX and XLS need the `excel` extra |
|
|
117
|
+
| Profile | available: `rowsift.profile(table)` finds the header, skips rows that are not data with a code, and gives each column a kind with its share, counts, the low-cardinality signal and masked samples |
|
|
118
|
+
| Clean | available: one cleaner per kind, `rowsift.clean.value` to dispatch by kind, masking functions. Phone numbers of a region other than Brazil need the `phone` extra |
|
|
119
|
+
| Map | available: `rowsift.suggest(profile, fields)` suggests a column for each declared `Field`, with a confidence level and reason codes. `SavedMapping` and `rowsift.apply_saved` carry a person's choices to the next file without guessing |
|
|
120
|
+
| Sift | available: `rowsift.sift(table, profile, mapping, fields)` returns the kept rows with their cleaned values and changes, the rejected rows with the field and issue code, and counts per field. It has no side effect, so it serves as a preview and as the final pass |
|
|
121
|
+
|
|
122
|
+
## Requirements
|
|
123
|
+
|
|
124
|
+
Python 3.11 to 3.14. The core has no runtime dependency.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pip install rowsift # core: CSV and delimited text
|
|
128
|
+
pip install "rowsift[excel]" # adds XLSX and XLS
|
|
129
|
+
pip install "rowsift[phone]" # adds phone numbers outside Brazil
|
|
130
|
+
pip install "rowsift[all]" # every extra
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
A function that needs an extra that is not installed raises `rowsift.MissingExtraError`, which names the extra.
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
You need [uv](https://docs.astral.sh/uv/) and [just](https://just.systems/).
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
just setup # install the project and its tools into .venv
|
|
141
|
+
just verify # lint, type check, tests, text check and build: exactly what CI runs
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request, and [SECURITY.md](SECURITY.md) to report a vulnerability.
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
[Apache License 2.0](LICENSE). You can use, modify and distribute the library, including in commercial and closed-source software, as long as you keep the license and the notices.
|
rowsift-0.1.1/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# rowsift
|
|
2
|
+
|
|
3
|
+
rowsift reads spreadsheets written by people and turns them into typed, clean rows mapped to the fields your application declares.
|
|
4
|
+
|
|
5
|
+
A file exported by a person is rarely a clean table. The header sits on the fourth row under a title and a blank line. The encoding is whatever the spreadsheet program chose. Phone numbers come in five formats, dates have no year, and the column you need is called `Cel 2`. rowsift handles that part of an import, on the server, and reports every decision it made so the application can show it to the person who sent the file.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
The work is split into four steps. Each one can be used on its own.
|
|
10
|
+
|
|
11
|
+
| Step | Input | Output |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| **Read** | bytes of a CSV, XLSX or XLS file | a grid of text cells, plus how it was read: format, encoding, delimiter, sheet |
|
|
14
|
+
| **Profile** | the grid | where the header is, which rows are data, and what each column holds: text, number, money, date, day and month, phone, e-mail, tax id, postal code, or a small set of repeated values |
|
|
15
|
+
| **Clean** | one value and the kind it should be | the normalized value, or the reason it could not be normalized |
|
|
16
|
+
| **Map** | the profile and the fields you declare | a suggested column for each field, with a confidence level and the reason for it |
|
|
17
|
+
|
|
18
|
+
Applying a mapping to a file gives typed rows, the rows that were rejected with the reason for each, and counts of what was changed.
|
|
19
|
+
|
|
20
|
+
## What it does not do
|
|
21
|
+
|
|
22
|
+
- It does not store anything. Models, jobs, uploads and screens belong to the application.
|
|
23
|
+
- It does not guess silently. A phone number cut short by an export is reported as cut short, never completed.
|
|
24
|
+
- It does not write user-facing text. Reasons are returned as codes with their data, so the application writes the message in its own language and tone.
|
|
25
|
+
- It does not depend on a web framework.
|
|
26
|
+
|
|
27
|
+
## Formats and conventions
|
|
28
|
+
|
|
29
|
+
Brazilian conventions are supported from the first version, because that is where the library started: day-first dates, decimal comma, CPF and CNPJ check digits, CEP, and mobile numbers written with or without the ninth digit. Region-specific behavior is selected through options, and the defaults are documented with each function.
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import rowsift
|
|
35
|
+
|
|
36
|
+
data = (
|
|
37
|
+
"Cadastro de clientes\n"
|
|
38
|
+
"\n"
|
|
39
|
+
"Nome;Celular;Nascimento\n"
|
|
40
|
+
"ana souza;(11) 91234-5678;03/04/1990\n"
|
|
41
|
+
"bruno lima;(11) 9123;15/08/1985\n"
|
|
42
|
+
).encode("utf-8")
|
|
43
|
+
|
|
44
|
+
table = rowsift.read(data)
|
|
45
|
+
profile = rowsift.profile(table)
|
|
46
|
+
|
|
47
|
+
fields = [
|
|
48
|
+
rowsift.Field("name", rowsift.Kind.NAME, required=True, aliases=("Nome",)),
|
|
49
|
+
rowsift.Field("phone", rowsift.Kind.PHONE, aliases=("Celular",)),
|
|
50
|
+
rowsift.Field("birthday", rowsift.Kind.DATE, aliases=("Nascimento",)),
|
|
51
|
+
]
|
|
52
|
+
mapping = rowsift.suggest(profile, fields)
|
|
53
|
+
result = rowsift.sift(table, profile, mapping, fields)
|
|
54
|
+
|
|
55
|
+
assert result.summary.kept == 2
|
|
56
|
+
assert result.rows[0].values["name"] == "Ana Souza"
|
|
57
|
+
assert result.rows[0].values["phone"] == "+5511912345678"
|
|
58
|
+
# A phone number cut short is reported, not completed.
|
|
59
|
+
assert result.rows[1].values["phone"] is None
|
|
60
|
+
assert result.rows[1].issues["phone"].code == "too_short"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The header was found under a title and a blank line, each column was matched to a field, and the second phone number came back with a reason code instead of a guess. The [quick start](https://github.com/msantino/rowsift/blob/main/docs/quick-start.md) walks through the same file step by step.
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
- [Quick start](https://github.com/msantino/rowsift/blob/main/docs/quick-start.md)
|
|
68
|
+
- [Reading](https://github.com/msantino/rowsift/blob/main/docs/reading.md): formats, encodings, limits, errors
|
|
69
|
+
- [Profiling](https://github.com/msantino/rowsift/blob/main/docs/profiling.md): the header, skipped rows, kinds
|
|
70
|
+
- [Cleaning](https://github.com/msantino/rowsift/blob/main/docs/cleaning.md): one function per kind, options, masking
|
|
71
|
+
- [Mapping](https://github.com/msantino/rowsift/blob/main/docs/mapping.md): suggestions, confidence, saved mappings
|
|
72
|
+
- [Sifting](https://github.com/msantino/rowsift/blob/main/docs/sifting.md): rows, rejections, counts
|
|
73
|
+
- [Codes](https://github.com/msantino/rowsift/blob/main/docs/codes.md): every code and what it means
|
|
74
|
+
|
|
75
|
+
## Status
|
|
76
|
+
|
|
77
|
+
Early development, version `0.1.1`. The API can still change between minor versions. Before `1.0.0`, a breaking change raises the minor version. Removing or renaming a public name or a code is a breaking change, and adding a code is a minor change.
|
|
78
|
+
|
|
79
|
+
| Step | State |
|
|
80
|
+
|---|---|
|
|
81
|
+
| Read | available: `rowsift.read(...)` turns CSV, XLSX and XLS bytes into a grid of text cells and a report, under explicit limits. XLSX and XLS need the `excel` extra |
|
|
82
|
+
| Profile | available: `rowsift.profile(table)` finds the header, skips rows that are not data with a code, and gives each column a kind with its share, counts, the low-cardinality signal and masked samples |
|
|
83
|
+
| Clean | available: one cleaner per kind, `rowsift.clean.value` to dispatch by kind, masking functions. Phone numbers of a region other than Brazil need the `phone` extra |
|
|
84
|
+
| Map | available: `rowsift.suggest(profile, fields)` suggests a column for each declared `Field`, with a confidence level and reason codes. `SavedMapping` and `rowsift.apply_saved` carry a person's choices to the next file without guessing |
|
|
85
|
+
| Sift | available: `rowsift.sift(table, profile, mapping, fields)` returns the kept rows with their cleaned values and changes, the rejected rows with the field and issue code, and counts per field. It has no side effect, so it serves as a preview and as the final pass |
|
|
86
|
+
|
|
87
|
+
## Requirements
|
|
88
|
+
|
|
89
|
+
Python 3.11 to 3.14. The core has no runtime dependency.
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pip install rowsift # core: CSV and delimited text
|
|
93
|
+
pip install "rowsift[excel]" # adds XLSX and XLS
|
|
94
|
+
pip install "rowsift[phone]" # adds phone numbers outside Brazil
|
|
95
|
+
pip install "rowsift[all]" # every extra
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A function that needs an extra that is not installed raises `rowsift.MissingExtraError`, which names the extra.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
You need [uv](https://docs.astral.sh/uv/) and [just](https://just.systems/).
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
just setup # install the project and its tools into .venv
|
|
106
|
+
just verify # lint, type check, tests, text check and build: exactly what CI runs
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request, and [SECURITY.md](SECURITY.md) to report a vulnerability.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
[Apache License 2.0](LICENSE). You can use, modify and distribute the library, including in commercial and closed-source software, as long as you keep the license and the notices.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
## Report a vulnerability
|
|
4
|
+
|
|
5
|
+
**Do not open a public issue for a vulnerability.**
|
|
6
|
+
|
|
7
|
+
Use GitHub's private reporting: on the **Security** tab of this repository, choose **Report a vulnerability**. The report reaches the maintainer only.
|
|
8
|
+
|
|
9
|
+
Include what you can: what the vulnerability allows, how to reproduce it, and the rowsift and Python versions. If a file is needed to reproduce it, build one with invented data.
|
|
10
|
+
|
|
11
|
+
You get an answer within 7 days. Please do not disclose the problem before a fix is available.
|
|
12
|
+
|
|
13
|
+
## What is in scope
|
|
14
|
+
|
|
15
|
+
rowsift parses files that come from untrusted people. These are treated as vulnerabilities:
|
|
16
|
+
|
|
17
|
+
- a file that makes the library use memory or time far beyond its documented limits, such as a compressed workbook that expands to a very large size;
|
|
18
|
+
- a file that makes the library read, write or execute anything outside the bytes it was given;
|
|
19
|
+
- personal data that ends up in an exception message, a log line or a report when the documentation says it is masked.
|
|
20
|
+
|
|
21
|
+
A wrong parsing result with no security consequence is a bug: open a regular issue.
|
|
22
|
+
|
|
23
|
+
## Supported versions
|
|
24
|
+
|
|
25
|
+
Only the latest released version receives security fixes.
|