Skip to content

Commit 02534c3

Browse files
committed
0.9.7
1 parent 615d209 commit 02534c3

File tree

15 files changed

+510
-514
lines changed

15 files changed

+510
-514
lines changed

CHANGELOG.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,97 @@
11
# Changelog
22

3+
## [0.9.7] - 2025-12-10
4+
5+
### Philosophy Change
6+
7+
Version 0.9.6 introduced SQLite for file tracking, blocked multiple workers, and added complex configuration. This was overengineered. func-to-web should be simple, fast, and reliable.
8+
9+
0.9.7 returns to simplicity with filesystem-based tracking, multiple workers support, and sensible defaults.
10+
11+
---
12+
13+
### Removed
14+
15+
- **SQLite Database**
16+
- No more database files or locks
17+
- File metadata encoded directly in filenames
18+
- Format: `{uuid}___{timestamp}___{filename}`
19+
20+
- **Parameters Removed**
21+
- `db_location` - no longer needed
22+
- `cleanup_hours` - now hardcoded to 1 hour
23+
24+
- **Workers Limitation**
25+
- `workers > 1` no longer blocked
26+
- Scale vertically without restrictions
27+
28+
### Added
29+
30+
- **Automatic Upload Cleanup**
31+
- New parameter: `auto_delete_uploads` (default: `True`)
32+
- Uploaded files deleted after function completes
33+
- Disable with `auto_delete_uploads=False` if needed
34+
35+
- **Directory Configuration**
36+
- New parameter: `uploads_dir` (default: `"./uploads"`)
37+
- New parameter: `returns_dir` (default: `"./returned_files"`)
38+
39+
### Changed
40+
41+
- **File Retention**
42+
- Returned files deleted 1 hour after creation (hardcoded)
43+
- No download tracking needed
44+
- Cleanup runs every hour automatically
45+
46+
- **Multiple Workers**
47+
- Now supported like any other Uvicorn option
48+
- Each worker runs independent cleanup
49+
- File operations are atomic, no conflicts
50+
51+
- **Architecture**
52+
- Removed `db_manager.py` module
53+
- Simplified `file_handler.py`
54+
- Faster startup (no database initialization)
55+
56+
### Fixed
57+
58+
- Database lock errors eliminated
59+
- Race conditions eliminated
60+
- Improved startup performance
61+
62+
### Documentation
63+
64+
- Updated all docs to remove SQLite references
65+
- Removed `db_location` and `cleanup_hours` from examples
66+
- Added `auto_delete_uploads` documentation
67+
- Updated API reference (removed `db_manager`)
68+
69+
### Migration from 0.9.6
70+
71+
**Before:**
72+
```python
73+
run(my_function, db_location="/data", cleanup_hours=48)
74+
```
75+
76+
**After:**
77+
```python
78+
run(my_function, uploads_dir="/data/uploads", returns_dir="/data/returns")
79+
# Files now expire after 1 hour (hardcoded)
80+
```
81+
82+
**Breaking Changes:**
83+
- `db_location` removed (use `returns_dir`)
84+
- `cleanup_hours` removed (hardcoded to 1 hour)
85+
- `func_to_web.db` no longer created
86+
87+
**Non-Breaking:**
88+
- `workers` parameter now supported
89+
- All other parameters unchanged
90+
91+
### Summary
92+
93+
0.9.6 was overengineered. 0.9.7 is simple again: no database, automatic cleanup, multiple workers supported. Filesystem operations are fast, atomic, and sufficient.
94+
395
## [0.9.6] - 2025-12-10
496

597
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Func To Web 0.9.6
1+
# Func To Web 0.9.7
22

33
[![PyPI version](https://img.shields.io/pypi/v/func-to-web.svg)](https://pypi.org/project/func-to-web/)
44
[![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)

docs/api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
show_source: true
1313
heading_level: 3
1414

15-
::: func_to_web.db_manager
16-
options:
17-
show_root_heading: true
18-
show_source: true
19-
heading_level: 3
20-
2115
::: func_to_web.file_handler
2216
options:
2317
show_root_heading: true

docs/downloads.md

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ run(create_multiple_files)
4444
- **Any file type**: PDF, Excel, ZIP, images, JSON, CSV, binary data, etc.
4545
- **Large files**: Uses streaming - handles GB+ files efficiently
4646
- **Clean UI**: List of files with individual download buttons
47-
- **Persistent registry**: Files tracked in SQLite database (thread-safe)
48-
- **1-hour grace period**: Files remain available for 1 hour after download
49-
- **Automatic cleanup**: Old files removed after 24 hours (configurable)
47+
- **Filesystem tracking**: Metadata encoded in filenames (no database required)
48+
- **1-hour retention**: Files available for 1 hour from creation (hardcoded)
49+
- **Automatic cleanup**: Files older than 1 hour removed every hour
5050

5151
## Working with Libraries
5252

@@ -90,47 +90,37 @@ run([create_pdf, create_excel, create_archive])
9090

9191
## Performance
9292

93-
- **No size limits**: Uses temporary files and streaming
93+
- **No size limits**: Handles very large files (GB+) in streaming mode
9494
- **Constant memory usage**: Regardless of file size
9595
- **Same efficiency as file uploads**: 8MB chunks
96-
- **SQLite registry**: Thread-safe file tracking with persistent database
96+
- **Filesystem-based**: Metadata encoded in filenames (no database)
9797
- **Background cleanup**: Non-blocking startup cleanup process
9898

9999
## File Cleanup & Retention
100100

101-
Generated files have a **smart cleanup lifecycle**:
101+
Generated files have a **simple 1-hour lifecycle**:
102102

103103
1. **Immediate availability**: Files ready for download right after generation
104-
2. **1-hour grace period**: After first download, files remain available for re-download for 1 hour
105-
3. **24-hour retention**: Files older than 24 hours are automatically cleaned up every hour while the server runs (and on startup)
106-
4. **Configurable**: Adjust retention period with `cleanup_hours` parameter
107-
```python
108-
# Default: 24-hour cleanup
109-
run(my_function)
110-
111-
# Custom: 6-hour cleanup
112-
run(my_function, cleanup_hours=6)
104+
2. **1-hour retention**: Files automatically deleted 1 hour after creation (hardcoded, non-configurable)
105+
3. **Automatic cleanup**: Cleanup runs on startup and every hour while server runs
106+
4. **No download tracking**: Files expire based on creation time, not download time
113107

114-
# Disable auto-cleanup
115-
run(my_function, cleanup_hours=0)
116-
```
117-
118-
**Database location** is also configurable:
108+
**Directory configuration:**
119109
```python
120-
# Default: func_to_web.db in current directory
110+
# Default directories
121111
run(my_function)
112+
# Returned files stored in: ./returned_files
122113

123-
# Custom location
124-
run(my_function, db_location="/path/to/data")
125-
126-
# Temporary (uses system temp dir)
127-
import tempfile
128-
run(my_function, db_location=tempfile.gettempdir())
114+
# Custom directory
115+
run(
116+
my_function,
117+
returns_dir="/path/to/returns"
118+
)
129119
```
130120

131121
## Auto-Healing
132122

133-
If a file is manually deleted from disk but still exists in the database, the system automatically detects this and cleans up the broken reference when someone tries to download it.
123+
If a file is manually deleted from disk, the system automatically detects this when someone tries to download it and returns a "File expired" error.
134124

135125
## What's Next?
136126

docs/files.md

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ When uploading files, you'll see real-time feedback:
6666

6767
## Working with Uploaded Files
6868

69-
Uploaded files are saved to temporary locations. You can access them as file paths:
69+
Uploaded files are saved to the uploads directory. You can access them as file paths:
7070
```python
7171
from func_to_web import run
7272
from func_to_web.types import ImageFile
@@ -81,62 +81,88 @@ def process_image(image: ImageFile):
8181
run(process_image)
8282
```
8383

84-
## File Cleanup for Uploaded Files
84+
## Automatic Upload Cleanup
8585

86-
**Important:** func-to-web does **not** automatically clean up uploaded files. They are saved to the system's temporary directory:
86+
By default, uploaded files are **automatically deleted** after your function finishes processing:
87+
```python
88+
from func_to_web import run
89+
from func_to_web.types import ImageFile
90+
from PIL import Image, ImageFilter
8791

88-
- **Linux/Mac**: `/tmp`
89-
- **Windows**: `%TEMP%` (typically `C:\Users\Username\AppData\Local\Temp`)
92+
def process_image(image: ImageFile):
93+
img = Image.open(image)
94+
result = img.filter(ImageFilter.BLUR)
95+
return result
96+
# File automatically deleted after return
9097

91-
### OS Cleanup Behavior
98+
run(process_image) # auto_delete_uploads=True by default
99+
```
92100

93-
| OS | Automatic Cleanup | When |
94-
|----|-------------------|------|
95-
| **Linux** | ✅ Yes | On restart (and often after 10 days) |
96-
| **macOS** | ✅ Yes | On restart (and after 3 days unused) |
97-
| **Windows** | ⚠️ Maybe | Only if Storage Sense is enabled (disabled by default) |
101+
**Disable auto-delete** if you need files to persist:
102+
```python
103+
run(process_image, auto_delete_uploads=False)
104+
```
105+
106+
**Configure upload directory:**
107+
```python
108+
run(
109+
process_image,
110+
uploads_dir="/path/to/uploads",
111+
auto_delete_uploads=True
112+
)
113+
```
98114

99-
**Warning for Windows users:** Files in `%TEMP%` can accumulate indefinitely unless you manually run Disk Cleanup or enable Storage Sense.
115+
## File Cleanup for Uploaded Files
116+
117+
**By default**, func-to-web **automatically cleans up** uploaded files after processing (`auto_delete_uploads=True`). This is the recommended behavior.
118+
119+
**If you disable auto-delete** (`auto_delete_uploads=False`), files remain in the uploads directory **indefinitely** until you manually delete them. The OS will **not** clean them automatically.
100120

101121
### Cleanup Options
102122

103-
**Option 1: Let the OS handle it** (simple, but unreliable on Windows)
123+
**Option 1: Use auto-delete (default, recommended)**
104124
```python
105125
def process_image(image: ImageFile):
106126
img = Image.open(image)
107-
return img.filter(ImageFilter.BLUR)
108-
# File remains in temp directory
127+
result = img.filter(ImageFilter.BLUR)
128+
return result
129+
# File automatically deleted after processing
130+
131+
run(process_image) # auto_delete_uploads=True by default
109132
```
110133

111-
**Option 2: Manual cleanup** (recommended for production)
134+
**Option 2: Disable auto-delete** (files persist indefinitely)
112135
```python
113-
import os
114-
115136
def process_image(image: ImageFile):
116-
try:
117-
img = Image.open(image)
118-
result = img.filter(ImageFilter.BLUR)
119-
return result
120-
finally:
121-
os.unlink(image) # Delete file immediately
137+
img = Image.open(image)
138+
return img.filter(ImageFilter.BLUR)
139+
# File remains in uploads directory forever
140+
141+
run(process_image, auto_delete_uploads=False)
122142
```
123143

124-
**Option 3: Process in-memory** (for small files)
144+
**When to disable auto-delete:**
145+
146+
- You need to access files after the function completes
147+
- Multiple functions need to process the same file
148+
- You're implementing your own cleanup logic
149+
150+
**If auto-delete is disabled**, you must manually clean up:
125151
```python
126152
import os
153+
from pathlib import Path
127154

128-
def process_image(image: ImageFile):
129-
with open(image, 'rb') as f:
130-
data = f.read()
131-
os.unlink(image) # Delete immediately after reading
132-
# Process data in memory...
155+
# Manual cleanup script
156+
uploads_dir = Path("./uploads")
157+
for file in uploads_dir.glob("upload_*"):
158+
os.unlink(file)
133159
```
134160

135-
**Recommendation:** For production applications, especially on Windows, implement manual cleanup (Option 2) to avoid disk space issues.
161+
**Recommendation:** Use the default `auto_delete_uploads=True` unless you have a specific reason to preserve uploaded files.
136162

137163
### Returned Files (Different Behavior)
138164

139-
Files you **return** using `FileResponse` are handled differently and **are** automatically cleaned up by func-to-web after 24 hours (configurable). See [File Downloads](downloads.md) for details.
165+
Files you **return** using `FileResponse` are handled differently and **are** automatically cleaned up by func-to-web after 1 hour (hardcoded). See [File Downloads](downloads.md) for details.
140166

141167
## Next Steps
142168

0 commit comments

Comments
 (0)