dumont 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.
dumont-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: dumont
3
+ Version: 0.1.0
4
+ Summary: Excel file generation tool with pivot tables
5
+ Author: Dumont Developer
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/example/dumont
8
+ Project-URL: Repository, https://github.com/example/dumont
9
+ Keywords: excel,pivot,pandas,xlwings,cli
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: pandas>=1.5.0
22
+ Requires-Dist: xlsxwriter>=3.0.0
23
+ Requires-Dist: click>=8.0.0
24
+ Requires-Dist: openpyxl>=3.0.0
25
+ Provides-Extra: xlwings
26
+ Requires-Dist: xlwings>=0.30.0; extra == "xlwings"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: black>=23.0.0; extra == "dev"
30
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
31
+
32
+ # Dumont
33
+
34
+ Excel file generation tool with data sheets and pivot tables.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ # Install with pip
40
+ pip install -e .
41
+
42
+ # Or install with xlwings support
43
+ pip install -e ".[xlwings]"
44
+ ```
45
+
46
+ ## CLI Usage
47
+
48
+ ### Generate Excel with sample data
49
+
50
+ ```bash
51
+ dumont generate -o sales_report.xlsx
52
+ ```
53
+
54
+ ### Generate from CSV/Excel input
55
+
56
+ ```bash
57
+ dumont generate -i data.csv -o report.xlsx
58
+ ```
59
+
60
+ ### Customize pivot table
61
+
62
+ ```bash
63
+ dumont generate -o report.xlsx \
64
+ --pivot-values Revenue \
65
+ --pivot-index Category \
66
+ --pivot-columns Region \
67
+ --aggfunc sum
68
+ ```
69
+
70
+ ### Use xlwings engine (requires Excel installed)
71
+
72
+ ```bash
73
+ dumont generate -o report.xlsx --engine xlwings
74
+ ```
75
+
76
+ ### Preview sample data
77
+
78
+ ```bash
79
+ dumont sample --rows 20
80
+ ```
81
+
82
+ ### Preview Excel file contents
83
+
84
+ ```bash
85
+ dumont preview report.xlsx --sheet Data --rows 10
86
+ ```
87
+
88
+ ### Get file information
89
+
90
+ ```bash
91
+ dumont info report.xlsx
92
+ ```
93
+
94
+ ## Python API Usage
95
+
96
+ ```python
97
+ from dumont import create_excel_with_pivot, generate_sample_data
98
+ import pandas as pd
99
+
100
+ # Generate with sample data
101
+ create_excel_with_pivot(
102
+ output_path="report.xlsx",
103
+ use_sample_data=True,
104
+ sample_rows=200,
105
+ )
106
+
107
+ # Use your own DataFrame
108
+ df = pd.read_csv("my_data.csv")
109
+ create_excel_with_pivot(
110
+ output_path="report.xlsx",
111
+ df=df,
112
+ pivot_values="Sales",
113
+ pivot_index="Product",
114
+ pivot_columns="Quarter",
115
+ pivot_aggfunc="sum",
116
+ )
117
+
118
+ # Use xlwings for native Excel features
119
+ from dumont import create_excel_with_xlwings
120
+
121
+ create_excel_with_xlwings(
122
+ output_path="report.xlsx",
123
+ use_sample_data=True,
124
+ visible=True, # Show Excel during creation
125
+ )
126
+ ```
127
+
128
+ ## Output Structure
129
+
130
+ The generated Excel file contains:
131
+
132
+ 1. **Data Sheet**: Raw data with auto-fitted columns
133
+ 2. **Pivot Sheet**: Pivot table summarizing the data with margins/totals
134
+
135
+ ## Requirements
136
+
137
+ - Python 3.8+
138
+ - pandas
139
+ - xlsxwriter
140
+ - click
141
+ - openpyxl
142
+ - xlwings (optional, for advanced Excel features)
dumont-0.1.0/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Dumont
2
+
3
+ Excel file generation tool with data sheets and pivot tables.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Install with pip
9
+ pip install -e .
10
+
11
+ # Or install with xlwings support
12
+ pip install -e ".[xlwings]"
13
+ ```
14
+
15
+ ## CLI Usage
16
+
17
+ ### Generate Excel with sample data
18
+
19
+ ```bash
20
+ dumont generate -o sales_report.xlsx
21
+ ```
22
+
23
+ ### Generate from CSV/Excel input
24
+
25
+ ```bash
26
+ dumont generate -i data.csv -o report.xlsx
27
+ ```
28
+
29
+ ### Customize pivot table
30
+
31
+ ```bash
32
+ dumont generate -o report.xlsx \
33
+ --pivot-values Revenue \
34
+ --pivot-index Category \
35
+ --pivot-columns Region \
36
+ --aggfunc sum
37
+ ```
38
+
39
+ ### Use xlwings engine (requires Excel installed)
40
+
41
+ ```bash
42
+ dumont generate -o report.xlsx --engine xlwings
43
+ ```
44
+
45
+ ### Preview sample data
46
+
47
+ ```bash
48
+ dumont sample --rows 20
49
+ ```
50
+
51
+ ### Preview Excel file contents
52
+
53
+ ```bash
54
+ dumont preview report.xlsx --sheet Data --rows 10
55
+ ```
56
+
57
+ ### Get file information
58
+
59
+ ```bash
60
+ dumont info report.xlsx
61
+ ```
62
+
63
+ ## Python API Usage
64
+
65
+ ```python
66
+ from dumont import create_excel_with_pivot, generate_sample_data
67
+ import pandas as pd
68
+
69
+ # Generate with sample data
70
+ create_excel_with_pivot(
71
+ output_path="report.xlsx",
72
+ use_sample_data=True,
73
+ sample_rows=200,
74
+ )
75
+
76
+ # Use your own DataFrame
77
+ df = pd.read_csv("my_data.csv")
78
+ create_excel_with_pivot(
79
+ output_path="report.xlsx",
80
+ df=df,
81
+ pivot_values="Sales",
82
+ pivot_index="Product",
83
+ pivot_columns="Quarter",
84
+ pivot_aggfunc="sum",
85
+ )
86
+
87
+ # Use xlwings for native Excel features
88
+ from dumont import create_excel_with_xlwings
89
+
90
+ create_excel_with_xlwings(
91
+ output_path="report.xlsx",
92
+ use_sample_data=True,
93
+ visible=True, # Show Excel during creation
94
+ )
95
+ ```
96
+
97
+ ## Output Structure
98
+
99
+ The generated Excel file contains:
100
+
101
+ 1. **Data Sheet**: Raw data with auto-fitted columns
102
+ 2. **Pivot Sheet**: Pivot table summarizing the data with margins/totals
103
+
104
+ ## Requirements
105
+
106
+ - Python 3.8+
107
+ - pandas
108
+ - xlsxwriter
109
+ - click
110
+ - openpyxl
111
+ - xlwings (optional, for advanced Excel features)
@@ -0,0 +1,17 @@
1
+ """Dumont - Excel file generation tool with pivot tables."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .core import (
6
+ create_excel_with_pivot,
7
+ create_data_sheet,
8
+ create_pivot_table,
9
+ generate_sample_data,
10
+ )
11
+
12
+ __all__ = [
13
+ "create_excel_with_pivot",
14
+ "create_data_sheet",
15
+ "create_pivot_table",
16
+ "generate_sample_data",
17
+ ]
@@ -0,0 +1,260 @@
1
+ """Command-line interface for Dumont Excel generator."""
2
+
3
+ import click
4
+ from pathlib import Path
5
+ from typing import Optional
6
+
7
+ from .core import (
8
+ create_excel_with_pivot,
9
+ create_excel_with_xlwings,
10
+ generate_sample_data,
11
+ read_excel_to_dataframe,
12
+ )
13
+
14
+
15
+ @click.group()
16
+ @click.version_option()
17
+ def cli():
18
+ """Dumont - Excel file generation tool with pivot tables.
19
+
20
+ Generate Excel files with data and pivot table sheets using pandas and xlwings.
21
+ """
22
+ pass
23
+
24
+
25
+ @cli.command()
26
+ @click.option(
27
+ "-o", "--output",
28
+ type=click.Path(),
29
+ default="output.xlsx",
30
+ help="Output Excel file path (default: output.xlsx)",
31
+ )
32
+ @click.option(
33
+ "-i", "--input",
34
+ "input_file",
35
+ type=click.Path(exists=True),
36
+ help="Input CSV or Excel file to use as data source",
37
+ )
38
+ @click.option(
39
+ "--data-sheet",
40
+ default="Data",
41
+ help="Name for the data sheet (default: Data)",
42
+ )
43
+ @click.option(
44
+ "--pivot-sheet",
45
+ default="Pivot",
46
+ help="Name for the pivot sheet (default: Pivot)",
47
+ )
48
+ @click.option(
49
+ "--pivot-values",
50
+ default="Revenue",
51
+ help="Column to aggregate in pivot table (default: Revenue)",
52
+ )
53
+ @click.option(
54
+ "--pivot-index",
55
+ default="Category",
56
+ help="Row grouping column for pivot (default: Category)",
57
+ )
58
+ @click.option(
59
+ "--pivot-columns",
60
+ default="Region",
61
+ help="Column grouping for pivot (default: Region)",
62
+ )
63
+ @click.option(
64
+ "--aggfunc",
65
+ type=click.Choice(["sum", "mean", "count", "min", "max"]),
66
+ default="sum",
67
+ help="Aggregation function (default: sum)",
68
+ )
69
+ @click.option(
70
+ "--sample/--no-sample",
71
+ default=True,
72
+ help="Use sample data if no input file provided (default: True)",
73
+ )
74
+ @click.option(
75
+ "--rows",
76
+ type=int,
77
+ default=100,
78
+ help="Number of rows for sample data (default: 100)",
79
+ )
80
+ @click.option(
81
+ "--engine",
82
+ type=click.Choice(["pandas", "xlwings"]),
83
+ default="pandas",
84
+ help="Excel engine to use (default: pandas)",
85
+ )
86
+ @click.option(
87
+ "--visible",
88
+ is_flag=True,
89
+ help="Show Excel window during xlwings creation",
90
+ )
91
+ def generate(
92
+ output: str,
93
+ input_file: Optional[str],
94
+ data_sheet: str,
95
+ pivot_sheet: str,
96
+ pivot_values: str,
97
+ pivot_index: str,
98
+ pivot_columns: str,
99
+ aggfunc: str,
100
+ sample: bool,
101
+ rows: int,
102
+ engine: str,
103
+ visible: bool,
104
+ ):
105
+ """Generate an Excel file with data and pivot table sheets.
106
+
107
+ Examples:
108
+
109
+ # Generate with sample data
110
+ dumont generate -o sales_report.xlsx
111
+
112
+ # Use custom input file
113
+ dumont generate -i data.csv -o report.xlsx
114
+
115
+ # Customize pivot table
116
+ dumont generate -o report.xlsx --pivot-values Sales --pivot-index Product
117
+
118
+ # Use xlwings engine with visible Excel
119
+ dumont generate -o report.xlsx --engine xlwings --visible
120
+ """
121
+ df = None
122
+
123
+ if input_file:
124
+ click.echo(f"Reading data from: {input_file}")
125
+ input_path = Path(input_file)
126
+ if input_path.suffix.lower() == ".csv":
127
+ import pandas as pd
128
+ df = pd.read_csv(input_file)
129
+ else:
130
+ df = read_excel_to_dataframe(input_file)
131
+ click.echo(f"Loaded {len(df)} rows")
132
+
133
+ try:
134
+ if engine == "xlwings":
135
+ result_path = create_excel_with_xlwings(
136
+ output_path=output,
137
+ df=df,
138
+ data_sheet_name=data_sheet,
139
+ pivot_sheet_name=pivot_sheet,
140
+ pivot_values=pivot_values,
141
+ pivot_index=pivot_index,
142
+ pivot_columns=pivot_columns,
143
+ use_sample_data=sample and df is None,
144
+ sample_rows=rows,
145
+ visible=visible,
146
+ )
147
+ else:
148
+ result_path = create_excel_with_pivot(
149
+ output_path=output,
150
+ df=df,
151
+ data_sheet_name=data_sheet,
152
+ pivot_sheet_name=pivot_sheet,
153
+ pivot_values=pivot_values,
154
+ pivot_index=pivot_index,
155
+ pivot_columns=pivot_columns,
156
+ pivot_aggfunc=aggfunc,
157
+ use_sample_data=sample and df is None,
158
+ sample_rows=rows,
159
+ )
160
+
161
+ click.echo(f"Excel file created: {result_path}")
162
+ click.echo(f" - Sheet '{data_sheet}': Raw data")
163
+ click.echo(f" - Sheet '{pivot_sheet}': Pivot table ({pivot_values} by {pivot_index} x {pivot_columns})")
164
+
165
+ except Exception as e:
166
+ click.echo(f"Error: {e}", err=True)
167
+ raise click.Abort()
168
+
169
+
170
+ @cli.command()
171
+ @click.option(
172
+ "--rows",
173
+ type=int,
174
+ default=10,
175
+ help="Number of sample rows to show (default: 10)",
176
+ )
177
+ def sample(rows: int):
178
+ """Show sample data that would be generated.
179
+
180
+ Example:
181
+ dumont sample --rows 20
182
+ """
183
+ df = generate_sample_data(rows=rows)
184
+ click.echo("Sample data preview:")
185
+ click.echo(df.to_string(index=False))
186
+
187
+
188
+ @cli.command()
189
+ @click.argument("file", type=click.Path(exists=True))
190
+ @click.option(
191
+ "--sheet",
192
+ help="Specific sheet to read",
193
+ )
194
+ @click.option(
195
+ "--rows",
196
+ type=int,
197
+ default=10,
198
+ help="Number of rows to display (default: 10)",
199
+ )
200
+ def preview(file: str, sheet: Optional[str], rows: int):
201
+ """Preview contents of an Excel file.
202
+
203
+ Example:
204
+ dumont preview report.xlsx --sheet Data --rows 20
205
+ """
206
+ import pandas as pd
207
+
208
+ try:
209
+ if sheet:
210
+ df = pd.read_excel(file, sheet_name=sheet)
211
+ click.echo(f"Sheet: {sheet}")
212
+ else:
213
+ xl = pd.ExcelFile(file)
214
+ click.echo(f"Available sheets: {', '.join(xl.sheet_names)}")
215
+ df = pd.read_excel(file, sheet_name=0)
216
+ click.echo(f"Showing first sheet: {xl.sheet_names[0]}")
217
+
218
+ click.echo(f"Shape: {df.shape[0]} rows x {df.shape[1]} columns")
219
+ click.echo()
220
+ click.echo(df.head(rows).to_string(index=False))
221
+
222
+ except Exception as e:
223
+ click.echo(f"Error reading file: {e}", err=True)
224
+ raise click.Abort()
225
+
226
+
227
+ @cli.command()
228
+ @click.argument("file", type=click.Path(exists=True))
229
+ def info(file: str):
230
+ """Show information about an Excel file.
231
+
232
+ Example:
233
+ dumont info report.xlsx
234
+ """
235
+ import pandas as pd
236
+ from pathlib import Path
237
+
238
+ file_path = Path(file)
239
+ click.echo(f"File: {file_path.name}")
240
+ click.echo(f"Size: {file_path.stat().st_size / 1024:.1f} KB")
241
+
242
+ try:
243
+ xl = pd.ExcelFile(file)
244
+ click.echo(f"Sheets: {len(xl.sheet_names)}")
245
+
246
+ for sheet_name in xl.sheet_names:
247
+ df = pd.read_excel(xl, sheet_name=sheet_name)
248
+ click.echo(f" - {sheet_name}: {df.shape[0]} rows x {df.shape[1]} columns")
249
+
250
+ except Exception as e:
251
+ click.echo(f"Error: {e}", err=True)
252
+
253
+
254
+ def main():
255
+ """Entry point for the CLI."""
256
+ cli()
257
+
258
+
259
+ if __name__ == "__main__":
260
+ main()
@@ -0,0 +1,289 @@
1
+ """Core Excel generation functions using pandas and xlwings."""
2
+
3
+ import pandas as pd
4
+ from pathlib import Path
5
+ from typing import Optional, Union, List, Dict, Any
6
+ from datetime import datetime, timedelta
7
+ import random
8
+
9
+
10
+ def generate_sample_data(rows: int = 100) -> pd.DataFrame:
11
+ """Generate sample sales data for demonstration purposes.
12
+
13
+ Args:
14
+ rows: Number of rows to generate.
15
+
16
+ Returns:
17
+ DataFrame with sample sales data.
18
+ """
19
+ random.seed(42)
20
+
21
+ categories = ["Electronics", "Clothing", "Food", "Books", "Home & Garden"]
22
+ regions = ["North", "South", "East", "West", "Central"]
23
+ products = {
24
+ "Electronics": ["Laptop", "Phone", "Tablet", "Headphones", "Camera"],
25
+ "Clothing": ["Shirt", "Pants", "Jacket", "Shoes", "Hat"],
26
+ "Food": ["Snacks", "Beverages", "Frozen", "Dairy", "Produce"],
27
+ "Books": ["Fiction", "Non-Fiction", "Technical", "Children", "Comics"],
28
+ "Home & Garden": ["Furniture", "Tools", "Decor", "Plants", "Lighting"],
29
+ }
30
+
31
+ data = []
32
+ base_date = datetime(2024, 1, 1)
33
+
34
+ for _ in range(rows):
35
+ category = random.choice(categories)
36
+ product = random.choice(products[category])
37
+ region = random.choice(regions)
38
+ date = base_date + timedelta(days=random.randint(0, 364))
39
+ quantity = random.randint(1, 50)
40
+ unit_price = round(random.uniform(10, 500), 2)
41
+ revenue = round(quantity * unit_price, 2)
42
+
43
+ data.append({
44
+ "Date": date,
45
+ "Category": category,
46
+ "Product": product,
47
+ "Region": region,
48
+ "Quantity": quantity,
49
+ "Unit_Price": unit_price,
50
+ "Revenue": revenue,
51
+ })
52
+
53
+ return pd.DataFrame(data)
54
+
55
+
56
+ def create_data_sheet(
57
+ df: pd.DataFrame,
58
+ writer: pd.ExcelWriter,
59
+ sheet_name: str = "Data",
60
+ format_as_table: bool = True,
61
+ ) -> None:
62
+ """Write a DataFrame to an Excel sheet.
63
+
64
+ Args:
65
+ df: DataFrame to write.
66
+ writer: ExcelWriter object.
67
+ sheet_name: Name of the sheet.
68
+ format_as_table: Whether to format as Excel table.
69
+ """
70
+ df.to_excel(writer, sheet_name=sheet_name, index=False)
71
+
72
+ workbook = writer.book
73
+ worksheet = writer.sheets[sheet_name]
74
+
75
+ # Auto-adjust column widths
76
+ for idx, col in enumerate(df.columns):
77
+ max_length = max(
78
+ df[col].astype(str).map(len).max(),
79
+ len(str(col))
80
+ ) + 2
81
+ worksheet.set_column(idx, idx, min(max_length, 50))
82
+
83
+
84
+ def create_pivot_table(
85
+ df: pd.DataFrame,
86
+ writer: pd.ExcelWriter,
87
+ sheet_name: str = "Pivot",
88
+ values: str = "Revenue",
89
+ index: Union[str, List[str]] = "Category",
90
+ columns: Optional[Union[str, List[str]]] = "Region",
91
+ aggfunc: str = "sum",
92
+ ) -> pd.DataFrame:
93
+ """Create a pivot table and write it to an Excel sheet.
94
+
95
+ Args:
96
+ df: Source DataFrame.
97
+ writer: ExcelWriter object.
98
+ sheet_name: Name of the pivot sheet.
99
+ values: Column to aggregate.
100
+ index: Row grouping column(s).
101
+ columns: Column grouping column(s).
102
+ aggfunc: Aggregation function ('sum', 'mean', 'count', etc.).
103
+
104
+ Returns:
105
+ The pivot table DataFrame.
106
+ """
107
+ pivot_df = pd.pivot_table(
108
+ df,
109
+ values=values,
110
+ index=index,
111
+ columns=columns,
112
+ aggfunc=aggfunc,
113
+ margins=True,
114
+ margins_name="Total",
115
+ )
116
+
117
+ # Round numeric values
118
+ pivot_df = pivot_df.round(2)
119
+
120
+ pivot_df.to_excel(writer, sheet_name=sheet_name)
121
+
122
+ workbook = writer.book
123
+ worksheet = writer.sheets[sheet_name]
124
+
125
+ # Auto-adjust column widths for pivot
126
+ for idx in range(len(pivot_df.columns) + 1):
127
+ worksheet.set_column(idx, idx, 15)
128
+
129
+ return pivot_df
130
+
131
+
132
+ def create_excel_with_pivot(
133
+ output_path: Union[str, Path],
134
+ df: Optional[pd.DataFrame] = None,
135
+ data_sheet_name: str = "Data",
136
+ pivot_sheet_name: str = "Pivot",
137
+ pivot_values: str = "Revenue",
138
+ pivot_index: Union[str, List[str]] = "Category",
139
+ pivot_columns: Optional[Union[str, List[str]]] = "Region",
140
+ pivot_aggfunc: str = "sum",
141
+ use_sample_data: bool = False,
142
+ sample_rows: int = 100,
143
+ ) -> Path:
144
+ """Create an Excel file with a data sheet and a pivot table sheet.
145
+
146
+ Args:
147
+ output_path: Path for the output Excel file.
148
+ df: DataFrame to use. If None and use_sample_data is True, generates sample data.
149
+ data_sheet_name: Name of the data sheet.
150
+ pivot_sheet_name: Name of the pivot table sheet.
151
+ pivot_values: Column to aggregate in pivot.
152
+ pivot_index: Row grouping for pivot.
153
+ pivot_columns: Column grouping for pivot.
154
+ pivot_aggfunc: Aggregation function for pivot.
155
+ use_sample_data: Generate sample data if df is None.
156
+ sample_rows: Number of rows for sample data.
157
+
158
+ Returns:
159
+ Path to the created Excel file.
160
+ """
161
+ output_path = Path(output_path)
162
+
163
+ if df is None:
164
+ if use_sample_data:
165
+ df = generate_sample_data(rows=sample_rows)
166
+ else:
167
+ raise ValueError("Either provide a DataFrame or set use_sample_data=True")
168
+
169
+ with pd.ExcelWriter(output_path, engine="xlsxwriter") as writer:
170
+ # Create data sheet
171
+ create_data_sheet(df, writer, sheet_name=data_sheet_name)
172
+
173
+ # Create pivot table sheet
174
+ create_pivot_table(
175
+ df,
176
+ writer,
177
+ sheet_name=pivot_sheet_name,
178
+ values=pivot_values,
179
+ index=pivot_index,
180
+ columns=pivot_columns,
181
+ aggfunc=pivot_aggfunc,
182
+ )
183
+
184
+ return output_path
185
+
186
+
187
+ def create_excel_with_xlwings(
188
+ output_path: Union[str, Path],
189
+ df: Optional[pd.DataFrame] = None,
190
+ data_sheet_name: str = "Data",
191
+ pivot_sheet_name: str = "Pivot",
192
+ pivot_values: str = "Revenue",
193
+ pivot_index: str = "Category",
194
+ pivot_columns: str = "Region",
195
+ use_sample_data: bool = False,
196
+ sample_rows: int = 100,
197
+ visible: bool = False,
198
+ ) -> Path:
199
+ """Create an Excel file using xlwings for more advanced features.
200
+
201
+ This function uses xlwings to interact with Excel directly,
202
+ enabling native Excel pivot tables and formatting.
203
+
204
+ Args:
205
+ output_path: Path for the output Excel file.
206
+ df: DataFrame to use.
207
+ data_sheet_name: Name of the data sheet.
208
+ pivot_sheet_name: Name of the pivot table sheet.
209
+ pivot_values: Column to aggregate in pivot.
210
+ pivot_index: Row grouping for pivot.
211
+ pivot_columns: Column grouping for pivot.
212
+ use_sample_data: Generate sample data if df is None.
213
+ sample_rows: Number of rows for sample data.
214
+ visible: Whether to show Excel during creation.
215
+
216
+ Returns:
217
+ Path to the created Excel file.
218
+ """
219
+ try:
220
+ import xlwings as xw
221
+ except ImportError:
222
+ raise ImportError("xlwings is required for this function. Install with: pip install xlwings")
223
+
224
+ output_path = Path(output_path)
225
+
226
+ if df is None:
227
+ if use_sample_data:
228
+ df = generate_sample_data(rows=sample_rows)
229
+ else:
230
+ raise ValueError("Either provide a DataFrame or set use_sample_data=True")
231
+
232
+ # Create workbook with xlwings
233
+ app = xw.App(visible=visible)
234
+ try:
235
+ wb = app.books.add()
236
+
237
+ # Add data sheet
238
+ data_sheet = wb.sheets[0]
239
+ data_sheet.name = data_sheet_name
240
+ data_sheet.range("A1").value = df
241
+
242
+ # Auto-fit columns
243
+ data_sheet.autofit()
244
+
245
+ # Add pivot sheet with pandas pivot (xlwings native pivot requires Excel COM)
246
+ pivot_df = pd.pivot_table(
247
+ df,
248
+ values=pivot_values,
249
+ index=pivot_index,
250
+ columns=pivot_columns,
251
+ aggfunc="sum",
252
+ margins=True,
253
+ margins_name="Total",
254
+ ).round(2)
255
+
256
+ pivot_sheet = wb.sheets.add(name=pivot_sheet_name, after=data_sheet)
257
+ pivot_sheet.range("A1").value = pivot_df
258
+ pivot_sheet.autofit()
259
+
260
+ # Format pivot table headers
261
+ header_range = pivot_sheet.range("A1").expand("right")
262
+ header_range.color = (66, 133, 244) # Blue
263
+ header_range.font.color = (255, 255, 255) # White
264
+ header_range.font.bold = True
265
+
266
+ # Save and close
267
+ wb.save(str(output_path))
268
+ wb.close()
269
+
270
+ finally:
271
+ app.quit()
272
+
273
+ return output_path
274
+
275
+
276
+ def read_excel_to_dataframe(
277
+ file_path: Union[str, Path],
278
+ sheet_name: Optional[str] = None,
279
+ ) -> pd.DataFrame:
280
+ """Read an Excel file into a DataFrame.
281
+
282
+ Args:
283
+ file_path: Path to the Excel file.
284
+ sheet_name: Specific sheet to read. If None, reads first sheet.
285
+
286
+ Returns:
287
+ DataFrame with the Excel data.
288
+ """
289
+ return pd.read_excel(file_path, sheet_name=sheet_name)
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: dumont
3
+ Version: 0.1.0
4
+ Summary: Excel file generation tool with pivot tables
5
+ Author: Dumont Developer
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/example/dumont
8
+ Project-URL: Repository, https://github.com/example/dumont
9
+ Keywords: excel,pivot,pandas,xlwings,cli
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: pandas>=1.5.0
22
+ Requires-Dist: xlsxwriter>=3.0.0
23
+ Requires-Dist: click>=8.0.0
24
+ Requires-Dist: openpyxl>=3.0.0
25
+ Provides-Extra: xlwings
26
+ Requires-Dist: xlwings>=0.30.0; extra == "xlwings"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: black>=23.0.0; extra == "dev"
30
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
31
+
32
+ # Dumont
33
+
34
+ Excel file generation tool with data sheets and pivot tables.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ # Install with pip
40
+ pip install -e .
41
+
42
+ # Or install with xlwings support
43
+ pip install -e ".[xlwings]"
44
+ ```
45
+
46
+ ## CLI Usage
47
+
48
+ ### Generate Excel with sample data
49
+
50
+ ```bash
51
+ dumont generate -o sales_report.xlsx
52
+ ```
53
+
54
+ ### Generate from CSV/Excel input
55
+
56
+ ```bash
57
+ dumont generate -i data.csv -o report.xlsx
58
+ ```
59
+
60
+ ### Customize pivot table
61
+
62
+ ```bash
63
+ dumont generate -o report.xlsx \
64
+ --pivot-values Revenue \
65
+ --pivot-index Category \
66
+ --pivot-columns Region \
67
+ --aggfunc sum
68
+ ```
69
+
70
+ ### Use xlwings engine (requires Excel installed)
71
+
72
+ ```bash
73
+ dumont generate -o report.xlsx --engine xlwings
74
+ ```
75
+
76
+ ### Preview sample data
77
+
78
+ ```bash
79
+ dumont sample --rows 20
80
+ ```
81
+
82
+ ### Preview Excel file contents
83
+
84
+ ```bash
85
+ dumont preview report.xlsx --sheet Data --rows 10
86
+ ```
87
+
88
+ ### Get file information
89
+
90
+ ```bash
91
+ dumont info report.xlsx
92
+ ```
93
+
94
+ ## Python API Usage
95
+
96
+ ```python
97
+ from dumont import create_excel_with_pivot, generate_sample_data
98
+ import pandas as pd
99
+
100
+ # Generate with sample data
101
+ create_excel_with_pivot(
102
+ output_path="report.xlsx",
103
+ use_sample_data=True,
104
+ sample_rows=200,
105
+ )
106
+
107
+ # Use your own DataFrame
108
+ df = pd.read_csv("my_data.csv")
109
+ create_excel_with_pivot(
110
+ output_path="report.xlsx",
111
+ df=df,
112
+ pivot_values="Sales",
113
+ pivot_index="Product",
114
+ pivot_columns="Quarter",
115
+ pivot_aggfunc="sum",
116
+ )
117
+
118
+ # Use xlwings for native Excel features
119
+ from dumont import create_excel_with_xlwings
120
+
121
+ create_excel_with_xlwings(
122
+ output_path="report.xlsx",
123
+ use_sample_data=True,
124
+ visible=True, # Show Excel during creation
125
+ )
126
+ ```
127
+
128
+ ## Output Structure
129
+
130
+ The generated Excel file contains:
131
+
132
+ 1. **Data Sheet**: Raw data with auto-fitted columns
133
+ 2. **Pivot Sheet**: Pivot table summarizing the data with margins/totals
134
+
135
+ ## Requirements
136
+
137
+ - Python 3.8+
138
+ - pandas
139
+ - xlsxwriter
140
+ - click
141
+ - openpyxl
142
+ - xlwings (optional, for advanced Excel features)
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ dumont/__init__.py
4
+ dumont/cli.py
5
+ dumont/core.py
6
+ dumont.egg-info/PKG-INFO
7
+ dumont.egg-info/SOURCES.txt
8
+ dumont.egg-info/dependency_links.txt
9
+ dumont.egg-info/entry_points.txt
10
+ dumont.egg-info/requires.txt
11
+ dumont.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dumont = dumont.cli:main
@@ -0,0 +1,12 @@
1
+ pandas>=1.5.0
2
+ xlsxwriter>=3.0.0
3
+ click>=8.0.0
4
+ openpyxl>=3.0.0
5
+
6
+ [dev]
7
+ pytest>=7.0.0
8
+ black>=23.0.0
9
+ ruff>=0.1.0
10
+
11
+ [xlwings]
12
+ xlwings>=0.30.0
@@ -0,0 +1 @@
1
+ dumont
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dumont"
7
+ version = "0.1.0"
8
+ description = "Excel file generation tool with pivot tables"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Dumont Developer"}
14
+ ]
15
+ keywords = ["excel", "pivot", "pandas", "xlwings", "cli"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ ]
27
+ dependencies = [
28
+ "pandas>=1.5.0",
29
+ "xlsxwriter>=3.0.0",
30
+ "click>=8.0.0",
31
+ "openpyxl>=3.0.0",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ xlwings = ["xlwings>=0.30.0"]
36
+ dev = [
37
+ "pytest>=7.0.0",
38
+ "black>=23.0.0",
39
+ "ruff>=0.1.0",
40
+ ]
41
+
42
+ [project.scripts]
43
+ dumont = "dumont.cli:main"
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/example/dumont"
47
+ Repository = "https://github.com/example/dumont"
48
+
49
+ [tool.setuptools.packages.find]
50
+ where = ["."]
51
+ include = ["dumont*"]
52
+
53
+ [tool.black]
54
+ line-length = 100
55
+ target-version = ["py38", "py39", "py310", "py311", "py312"]
56
+
57
+ [tool.ruff]
58
+ line-length = 100
59
+ select = ["E", "F", "W", "I", "N"]
dumont-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+