fwforge 0.1.0__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.
fwforge-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TallowX92
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
fwforge-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: fwforge
3
+ Version: 0.1.0
4
+ Summary: Fixed-width file parser for legacy logistics & supply chain data
5
+ Author-email: TallowX92 <tallow072@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/TallowX92/fwforge
8
+ Project-URL: Repository, https://github.com/TallowX92/fwforge
9
+ Project-URL: Issues, https://github.com/TallowX92/fwforge/issues
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pyyaml>=6.0
14
+ Dynamic: license-file
15
+
16
+ # FixedWidth Forge
17
+
18
+ [![PyPI version](https://img.shields.io/pypi/v/fwforge.svg)](https://pypi.org/project/fwforge/)
19
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fwforge)](https://pypi.org/project/fwforge/)
20
+ [![GitHub](https://img.shields.io/github/license/TallowX92/fwforge)](https://github.com/TallowX92/fwforge)
21
+
22
+ **Parse legacy fixed-width files from logistics, warehouses, ERP systems, and mainframes — instantly.**
23
+
24
+ Turn messy carrier reports, shipment manifests, and COBOL exports into clean CSV or JSON with a simple YAML schema.
25
+
26
+ ## Why Logistics & Supply Chain?
27
+ Legacy formats like **fixed-width flat files**, **EDI**, and proprietary mainframes are the glue of the supply chain. `fwforge` provides the bridge to modern data pipelines without the enterprise bloat.
28
+
29
+ ## Features
30
+ - **Schema-Driven**: Define column layouts in YAML. Supports `start+length` or `start+end` positions.
31
+ - **Ultra-Fast**: Built on Python principles for rapid parsing of multi-gigabyte flat files.
32
+ - **Batch Processing**: Process entire directories of manifest exports with one command.
33
+ - **Inference Engine**: Use `--infer` to automatically generate a baseline schema from a sample data file.
34
+ - **Clean Output**: Transform legacy data to clean CSV or JSON with built-in type casting.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install fwforge
40
+ ```
41
+
42
+ Install from source (latest dev):
43
+
44
+ ```bash
45
+ pip install git+https://github.com/TallowX92/fwforge.git
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ### 1. Infer a schema
51
+ Start from scratch with a sample file:
52
+ ```bash
53
+ fwforge --infer -i data.txt > my-layout.yaml
54
+ ```
55
+
56
+ ### 2. Parse data
57
+ Convert legacy data to CSV (using the included sample):
58
+ ```bash
59
+ fwforge -i data.txt -s layout.yaml -f csv -o output.csv
60
+ cat output.csv
61
+ ```
62
+
63
+ ### 3. Batch process a folder
64
+ ```bash
65
+ fwforge -i ./daily_manifests/ -s manifest.yaml -f json
66
+ ```
67
+
68
+ ## Example Schema (`layout.yaml`)
69
+ ```yaml
70
+ name: "Freight-Manifest-v1"
71
+ columns:
72
+ - name: "carrier_code"
73
+ start: 0
74
+ length: 5
75
+ trim: true
76
+ type: "string"
77
+ - name: "weight"
78
+ start: 20
79
+ length: 10
80
+ trim: true
81
+ type: "float"
82
+ ```
83
+
84
+ ## Development
85
+
86
+ ```bash
87
+ # Clone and setup
88
+ git clone https://github.com/TallowX92/fwforge.git
89
+ cd fwforge
90
+ uv sync
91
+ uv run pytest -v
92
+
93
+ # Run CLI
94
+ uv run fwforge --help
95
+ ```
96
+
97
+ ## Roadmap
98
+
99
+ - More robust type casting (dates, currency, custom)
100
+ - Schema validation + strict mode
101
+ - Better inference (header detection, multi-line records)
102
+ - Performance / memory improvements for GB+ files
103
+ - Standalone binary releases
104
+ - Expanded output formats (parquet, etc.)
105
+
106
+ ## Changelog
107
+
108
+ See [CHANGELOG.md](CHANGELOG.md) for release notes.
@@ -0,0 +1,93 @@
1
+ # FixedWidth Forge
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/fwforge.svg)](https://pypi.org/project/fwforge/)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fwforge)](https://pypi.org/project/fwforge/)
5
+ [![GitHub](https://img.shields.io/github/license/TallowX92/fwforge)](https://github.com/TallowX92/fwforge)
6
+
7
+ **Parse legacy fixed-width files from logistics, warehouses, ERP systems, and mainframes — instantly.**
8
+
9
+ Turn messy carrier reports, shipment manifests, and COBOL exports into clean CSV or JSON with a simple YAML schema.
10
+
11
+ ## Why Logistics & Supply Chain?
12
+ Legacy formats like **fixed-width flat files**, **EDI**, and proprietary mainframes are the glue of the supply chain. `fwforge` provides the bridge to modern data pipelines without the enterprise bloat.
13
+
14
+ ## Features
15
+ - **Schema-Driven**: Define column layouts in YAML. Supports `start+length` or `start+end` positions.
16
+ - **Ultra-Fast**: Built on Python principles for rapid parsing of multi-gigabyte flat files.
17
+ - **Batch Processing**: Process entire directories of manifest exports with one command.
18
+ - **Inference Engine**: Use `--infer` to automatically generate a baseline schema from a sample data file.
19
+ - **Clean Output**: Transform legacy data to clean CSV or JSON with built-in type casting.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install fwforge
25
+ ```
26
+
27
+ Install from source (latest dev):
28
+
29
+ ```bash
30
+ pip install git+https://github.com/TallowX92/fwforge.git
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ### 1. Infer a schema
36
+ Start from scratch with a sample file:
37
+ ```bash
38
+ fwforge --infer -i data.txt > my-layout.yaml
39
+ ```
40
+
41
+ ### 2. Parse data
42
+ Convert legacy data to CSV (using the included sample):
43
+ ```bash
44
+ fwforge -i data.txt -s layout.yaml -f csv -o output.csv
45
+ cat output.csv
46
+ ```
47
+
48
+ ### 3. Batch process a folder
49
+ ```bash
50
+ fwforge -i ./daily_manifests/ -s manifest.yaml -f json
51
+ ```
52
+
53
+ ## Example Schema (`layout.yaml`)
54
+ ```yaml
55
+ name: "Freight-Manifest-v1"
56
+ columns:
57
+ - name: "carrier_code"
58
+ start: 0
59
+ length: 5
60
+ trim: true
61
+ type: "string"
62
+ - name: "weight"
63
+ start: 20
64
+ length: 10
65
+ trim: true
66
+ type: "float"
67
+ ```
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ # Clone and setup
73
+ git clone https://github.com/TallowX92/fwforge.git
74
+ cd fwforge
75
+ uv sync
76
+ uv run pytest -v
77
+
78
+ # Run CLI
79
+ uv run fwforge --help
80
+ ```
81
+
82
+ ## Roadmap
83
+
84
+ - More robust type casting (dates, currency, custom)
85
+ - Schema validation + strict mode
86
+ - Better inference (header detection, multi-line records)
87
+ - Performance / memory improvements for GB+ files
88
+ - Standalone binary releases
89
+ - Expanded output formats (parquet, etc.)
90
+
91
+ ## Changelog
92
+
93
+ See [CHANGELOG.md](CHANGELOG.md) for release notes.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fwforge"
7
+ version = "0.1.0"
8
+ description = "Fixed-width file parser for legacy logistics & supply chain data"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.9"
13
+ authors = [
14
+ {name = "TallowX92", email = "tallow072@gmail.com"}
15
+ ]
16
+ dependencies = [
17
+ "pyyaml>=6.0",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/TallowX92/fwforge"
22
+ Repository = "https://github.com/TallowX92/fwforge"
23
+ Issues = "https://github.com/TallowX92/fwforge/issues"
24
+
25
+ [project.scripts]
26
+ fwforge = "fwforge.cli:main"
27
+
28
+ [tool.setuptools.packages.find]
29
+ where = ["src"]
30
+
31
+ [dependency-groups]
32
+ dev = [
33
+ "pytest>=8.0",
34
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .cli import main
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,103 @@
1
+ import argparse
2
+ import sys
3
+ import yaml
4
+ import os
5
+ from .fw_parser import FixedWidthParser
6
+ from .writer import write_csv, write_json
7
+
8
+ def infer_layout(filepath):
9
+ try:
10
+ with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
11
+ line = f.readline().rstrip('\n\r')
12
+
13
+ columns = []
14
+ import re
15
+ for match in re.finditer(r'\S+', line):
16
+ columns.append({
17
+ "name": f"col_{match.start()}",
18
+ "start": match.start(),
19
+ "length": match.end() - match.start(),
20
+ "trim": True,
21
+ "type": "string"
22
+ })
23
+ return {"name": "InferredLayout", "columns": columns}
24
+ except FileNotFoundError:
25
+ print(f"Error: File '{filepath}' not found.", file=sys.stderr)
26
+ sys.exit(1)
27
+
28
+ def process_file(input_path, output, layout, format_type):
29
+ try:
30
+ column_names = [col['name'] for col in layout['columns']]
31
+ file_parser = FixedWidthParser(layout)
32
+
33
+ records = []
34
+ with open(input_path, 'r', encoding='utf-8', errors='replace') as f:
35
+ for line in f:
36
+ line = line.rstrip('\n\r')
37
+ if line.strip():
38
+ records.append(file_parser.parse_line(line))
39
+
40
+ if format_type == "csv":
41
+ write_csv(records, column_names, output)
42
+ else:
43
+ write_json(records, output)
44
+
45
+ except Exception as e:
46
+ print(f"Error processing {input_path}: {e}", file=sys.stderr)
47
+ finally:
48
+ if output is not sys.stdout:
49
+ output.close()
50
+
51
+ def main():
52
+ parser = argparse.ArgumentParser(description="FixedWidth Forge: Legacy data parser")
53
+ parser.add_argument("-i", "--input", required=True, help="Input file or directory")
54
+ parser.add_argument("-s", "--schema", help="YAML schema file")
55
+ parser.add_argument("-f", "--format", choices=["csv", "json"], default="csv")
56
+ parser.add_argument("-o", "--output", help="Output file or directory")
57
+ parser.add_argument("--infer", action="store_true", help="Infer schema from input file")
58
+ args = parser.parse_args()
59
+
60
+ if args.infer:
61
+ layout = infer_layout(args.input)
62
+ print(yaml.dump(layout))
63
+ return
64
+
65
+ if not args.schema:
66
+ parser.error("the following arguments are required: -s/--schema")
67
+
68
+ try:
69
+ with open(args.schema, 'r') as f:
70
+ layout = yaml.safe_load(f)
71
+ except FileNotFoundError:
72
+ print(f"Error: Schema file '{args.schema}' not found.", file=sys.stderr)
73
+ sys.exit(1)
74
+
75
+ if os.path.isdir(args.input):
76
+ output_dir = args.output or args.input
77
+ if not os.path.exists(output_dir):
78
+ os.makedirs(output_dir)
79
+
80
+ for filename in os.listdir(args.input):
81
+ if filename.endswith((".txt", ".fwf")):
82
+ input_path = os.path.join(args.input, filename)
83
+ output_filename = os.path.splitext(filename)[0] + "." + args.format
84
+ output_path = os.path.join(output_dir, output_filename)
85
+ print(f"Processing {input_path} -> {output_path}")
86
+ try:
87
+ with open(output_path, 'w', encoding='utf-8', newline='') as out_file:
88
+ process_file(input_path, out_file, layout, args.format)
89
+ except Exception as e:
90
+ print(f"Error writing to {output_path}: {e}", file=sys.stderr)
91
+ else:
92
+ try:
93
+ output = open(args.output, 'w', encoding='utf-8', newline='') if args.output else sys.stdout
94
+ process_file(args.input, output, layout, args.format)
95
+ except FileNotFoundError:
96
+ print(f"Error: Input file '{args.input}' not found.", file=sys.stderr)
97
+ sys.exit(1)
98
+ except Exception as e:
99
+ print(f"Error: {e}", file=sys.stderr)
100
+ sys.exit(1)
101
+
102
+ if __name__ == "__main__":
103
+ main()
@@ -0,0 +1,47 @@
1
+ from typing import Any, Dict, List
2
+
3
+ class FixedWidthParser:
4
+ def __init__(self, layout: Dict):
5
+ self.layout = layout
6
+ self.columns = layout.get('columns', [])
7
+
8
+ def parse_line(self, line: str) -> Dict[str, Any]:
9
+ record = {}
10
+ for col in self.columns:
11
+ start = col.get('start', 0)
12
+ # Support both length and end
13
+ if 'length' in col:
14
+ end = start + col['length']
15
+ elif 'end' in col:
16
+ end = col['end']
17
+ else:
18
+ end = start # Default to zero-length if neither provided
19
+
20
+ trim = col.get('trim', True)
21
+
22
+ if end > len(line):
23
+ val = line[start:].strip() if trim else line[start:]
24
+ else:
25
+ val = line[start:end]
26
+ if trim:
27
+ val = val.strip()
28
+
29
+ # Basic type conversion
30
+ record[col['name']] = self._cast_value(val, col.get('type', 'string'))
31
+
32
+ return record
33
+
34
+ def _cast_value(self, value: str, col_type: str) -> Any:
35
+ if not value:
36
+ return None if col_type in ('int', 'float') else ""
37
+
38
+ try:
39
+ if col_type == 'int':
40
+ return int(value)
41
+ elif col_type == 'float':
42
+ return float(value)
43
+ elif col_type == 'string':
44
+ return value
45
+ except ValueError:
46
+ pass # fallback to string
47
+ return value
@@ -0,0 +1,11 @@
1
+ import csv
2
+ import json
3
+ import sys
4
+
5
+ def write_csv(records, columns, output=sys.stdout):
6
+ writer = csv.DictWriter(output, fieldnames=columns)
7
+ writer.writeheader()
8
+ writer.writerows(records)
9
+
10
+ def write_json(records, output=sys.stdout):
11
+ json.dump(records, output, indent=2)
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: fwforge
3
+ Version: 0.1.0
4
+ Summary: Fixed-width file parser for legacy logistics & supply chain data
5
+ Author-email: TallowX92 <tallow072@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/TallowX92/fwforge
8
+ Project-URL: Repository, https://github.com/TallowX92/fwforge
9
+ Project-URL: Issues, https://github.com/TallowX92/fwforge/issues
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pyyaml>=6.0
14
+ Dynamic: license-file
15
+
16
+ # FixedWidth Forge
17
+
18
+ [![PyPI version](https://img.shields.io/pypi/v/fwforge.svg)](https://pypi.org/project/fwforge/)
19
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fwforge)](https://pypi.org/project/fwforge/)
20
+ [![GitHub](https://img.shields.io/github/license/TallowX92/fwforge)](https://github.com/TallowX92/fwforge)
21
+
22
+ **Parse legacy fixed-width files from logistics, warehouses, ERP systems, and mainframes — instantly.**
23
+
24
+ Turn messy carrier reports, shipment manifests, and COBOL exports into clean CSV or JSON with a simple YAML schema.
25
+
26
+ ## Why Logistics & Supply Chain?
27
+ Legacy formats like **fixed-width flat files**, **EDI**, and proprietary mainframes are the glue of the supply chain. `fwforge` provides the bridge to modern data pipelines without the enterprise bloat.
28
+
29
+ ## Features
30
+ - **Schema-Driven**: Define column layouts in YAML. Supports `start+length` or `start+end` positions.
31
+ - **Ultra-Fast**: Built on Python principles for rapid parsing of multi-gigabyte flat files.
32
+ - **Batch Processing**: Process entire directories of manifest exports with one command.
33
+ - **Inference Engine**: Use `--infer` to automatically generate a baseline schema from a sample data file.
34
+ - **Clean Output**: Transform legacy data to clean CSV or JSON with built-in type casting.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install fwforge
40
+ ```
41
+
42
+ Install from source (latest dev):
43
+
44
+ ```bash
45
+ pip install git+https://github.com/TallowX92/fwforge.git
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ### 1. Infer a schema
51
+ Start from scratch with a sample file:
52
+ ```bash
53
+ fwforge --infer -i data.txt > my-layout.yaml
54
+ ```
55
+
56
+ ### 2. Parse data
57
+ Convert legacy data to CSV (using the included sample):
58
+ ```bash
59
+ fwforge -i data.txt -s layout.yaml -f csv -o output.csv
60
+ cat output.csv
61
+ ```
62
+
63
+ ### 3. Batch process a folder
64
+ ```bash
65
+ fwforge -i ./daily_manifests/ -s manifest.yaml -f json
66
+ ```
67
+
68
+ ## Example Schema (`layout.yaml`)
69
+ ```yaml
70
+ name: "Freight-Manifest-v1"
71
+ columns:
72
+ - name: "carrier_code"
73
+ start: 0
74
+ length: 5
75
+ trim: true
76
+ type: "string"
77
+ - name: "weight"
78
+ start: 20
79
+ length: 10
80
+ trim: true
81
+ type: "float"
82
+ ```
83
+
84
+ ## Development
85
+
86
+ ```bash
87
+ # Clone and setup
88
+ git clone https://github.com/TallowX92/fwforge.git
89
+ cd fwforge
90
+ uv sync
91
+ uv run pytest -v
92
+
93
+ # Run CLI
94
+ uv run fwforge --help
95
+ ```
96
+
97
+ ## Roadmap
98
+
99
+ - More robust type casting (dates, currency, custom)
100
+ - Schema validation + strict mode
101
+ - Better inference (header detection, multi-line records)
102
+ - Performance / memory improvements for GB+ files
103
+ - Standalone binary releases
104
+ - Expanded output formats (parquet, etc.)
105
+
106
+ ## Changelog
107
+
108
+ See [CHANGELOG.md](CHANGELOG.md) for release notes.
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/fwforge/__init__.py
5
+ src/fwforge/__main__.py
6
+ src/fwforge/cli.py
7
+ src/fwforge/fw_parser.py
8
+ src/fwforge/writer.py
9
+ src/fwforge.egg-info/PKG-INFO
10
+ src/fwforge.egg-info/SOURCES.txt
11
+ src/fwforge.egg-info/dependency_links.txt
12
+ src/fwforge.egg-info/entry_points.txt
13
+ src/fwforge.egg-info/requires.txt
14
+ src/fwforge.egg-info/top_level.txt
15
+ tests/test_parser.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ fwforge = fwforge.cli:main
@@ -0,0 +1 @@
1
+ pyyaml>=6.0
@@ -0,0 +1 @@
1
+ fwforge
@@ -0,0 +1,43 @@
1
+ import pytest
2
+ from fwforge.fw_parser import FixedWidthParser
3
+
4
+ def test_basic_parsing():
5
+ layout = {
6
+ "columns": [
7
+ {"name": "a", "start": 0, "length": 3, "trim": True, "type": "string"},
8
+ {"name": "b", "start": 3, "length": 2, "trim": True, "type": "int"}
9
+ ]
10
+ }
11
+ parser = FixedWidthParser(layout)
12
+ line = "ABC10"
13
+ assert parser.parse_line(line) == {"a": "ABC", "b": 10}
14
+
15
+ def test_start_end_parsing():
16
+ layout = {
17
+ "columns": [
18
+ {"name": "a", "start": 0, "end": 3, "trim": True, "type": "string"},
19
+ ]
20
+ }
21
+ parser = FixedWidthParser(layout)
22
+ line = "ABC10"
23
+ assert parser.parse_line(line) == {"a": "ABC"}
24
+
25
+ def test_short_line_handling():
26
+ layout = {
27
+ "columns": [
28
+ {"name": "a", "start": 0, "length": 5, "trim": False, "type": "string"},
29
+ ]
30
+ }
31
+ parser = FixedWidthParser(layout)
32
+ line = "AB"
33
+ # Should handle end > len(line)
34
+ assert parser.parse_line(line) == {"a": "AB"}
35
+
36
+ def test_float_casting():
37
+ layout = {
38
+ "columns": [
39
+ {"name": "weight", "start": 0, "length": 5, "trim": True, "type": "float"},
40
+ ]
41
+ }
42
+ parser = FixedWidthParser(layout)
43
+ assert parser.parse_line("10.5 ") == {"weight": 10.5}