simple-file-utils 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.
- simple_file_utils-0.1.0/LICENSE +21 -0
- simple_file_utils-0.1.0/PKG-INFO +216 -0
- simple_file_utils-0.1.0/README.md +194 -0
- simple_file_utils-0.1.0/pyproject.toml +32 -0
- simple_file_utils-0.1.0/setup.cfg +4 -0
- simple_file_utils-0.1.0/simple_file_utils/__init__.py +13 -0
- simple_file_utils-0.1.0/simple_file_utils/core.py +76 -0
- simple_file_utils-0.1.0/simple_file_utils.egg-info/PKG-INFO +216 -0
- simple_file_utils-0.1.0/simple_file_utils.egg-info/SOURCES.txt +9 -0
- simple_file_utils-0.1.0/simple_file_utils.egg-info/dependency_links.txt +1 -0
- simple_file_utils-0.1.0/simple_file_utils.egg-info/top_level.txt +3 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 M R Darshan
|
|
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.
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simple-file-utils
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A beginner-friendly library for simplified file handling in Python.
|
|
5
|
+
Author: M R Darshan
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# ๐ Simple File Utils
|
|
24
|
+
|
|
25
|
+
A lightweight Python library for simplified file handling operations.
|
|
26
|
+
It provides easy-to-use functions for working with text, CSV, JSON, and binary files.
|
|
27
|
+
|
|
28
|
+
### โจ Features
|
|
29
|
+
|
|
30
|
+
- Read / Write / Append TXT files
|
|
31
|
+
- Read / Write / Append CSV files
|
|
32
|
+
- Read / Write JSON files
|
|
33
|
+
- Binary file support using pickle
|
|
34
|
+
- Utility helpers:
|
|
35
|
+
- `exists()`
|
|
36
|
+
- `delete()`
|
|
37
|
+
- `file_size()`
|
|
38
|
+
- `get_extension()`
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### ๐ฆ Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install simple-file-utils
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### ๐ Quickstart
|
|
50
|
+
```bash
|
|
51
|
+
import simple_file_utils as sfu
|
|
52
|
+
```
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## ๐ TXT FILE FUNCTIONS
|
|
56
|
+
|
|
57
|
+
`write_txt(file_path, data)`
|
|
58
|
+
|
|
59
|
+
Writes text to a file (overwrites if it exists).
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
sfu.write_txt("example.txt", "Hello World")
|
|
63
|
+
```
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
`read_txt(file_path)`
|
|
67
|
+
|
|
68
|
+
Reads entire file content as a string.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
content = sfu.read_txt("example.txt")
|
|
72
|
+
print(content)
|
|
73
|
+
```
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
`readlines_txt(file_path)`
|
|
77
|
+
|
|
78
|
+
Returns file content as a list of lines.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
lines = sfu.readlines_txt("example.txt")
|
|
82
|
+
print(lines)
|
|
83
|
+
```
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
`append_txt(file_path, data)`
|
|
87
|
+
|
|
88
|
+
Appends text to an existing file.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
sfu.append_txt("example.txt", "\nNew line added")
|
|
92
|
+
```
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## ๐ CSV FILE FUNCTIONS
|
|
96
|
+
`write_csv(file_path, rows)`
|
|
97
|
+
|
|
98
|
+
Writes a list of rows to a CSV file.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
rows = [
|
|
102
|
+
["Name", "Age"],
|
|
103
|
+
["John",18]
|
|
104
|
+
]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
sfu.write_csv("data.csv", rows)
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
`read_csv(file_path)`
|
|
111
|
+
|
|
112
|
+
Reads CSV file and returns list of rows.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
data = sfu.read_csv("data.csv")
|
|
116
|
+
print(data)
|
|
117
|
+
```
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
`append_csv(file_path, rows)`
|
|
121
|
+
|
|
122
|
+
Appends rows to an existing CSV file.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
sfu.append_csv("data.csv", [["Alex", 22]])
|
|
126
|
+
```
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## ๐งพ JSON Functions
|
|
130
|
+
`write_json(file_path, data)`
|
|
131
|
+
|
|
132
|
+
Writes a dictionary or list to a JSON file.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
user = {
|
|
136
|
+
"name": "John",
|
|
137
|
+
"age": 18
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
sfu.write_json("user.json", user)
|
|
141
|
+
```
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
`read_json(file_path)`
|
|
145
|
+
|
|
146
|
+
Reads JSON file and returns Python object.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
data = sfu.read_json("user.json")
|
|
150
|
+
print(data)
|
|
151
|
+
```
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## ๐พ Binary Functions
|
|
155
|
+
`write_bin(file_path, data)`
|
|
156
|
+
|
|
157
|
+
Saves a Python object to a binary file.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
numbers = [1, 2, 3, 4]
|
|
161
|
+
sfu.write_bin("numbers.bin", numbers)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`read_bin(file_path)`
|
|
165
|
+
|
|
166
|
+
Loads a Python object from a binary file.
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
numbers = sfu.read_bin("numbers.bin")
|
|
170
|
+
print(numbers)
|
|
171
|
+
```
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## ๐ Utility Functions
|
|
175
|
+
`exists(file_path)`
|
|
176
|
+
|
|
177
|
+
Checks if file exists.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
print(sfu.exists("example.txt"))
|
|
181
|
+
```
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
`delete(file_path)`
|
|
185
|
+
|
|
186
|
+
Deletes a file.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
sfu.delete("example.txt")
|
|
190
|
+
```
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
`file_size(file_path)`
|
|
194
|
+
|
|
195
|
+
Returns file size in bytes.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
size = sfu.file_size("data.csv")
|
|
199
|
+
print(size)
|
|
200
|
+
```
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
`get_extension(file_path)`
|
|
204
|
+
|
|
205
|
+
Returns file extension in lowercase.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
print(sfu.get_extension("data.csv")) # .csv
|
|
209
|
+
```
|
|
210
|
+
---
|
|
211
|
+
## ๐ฏ Why Use This Library?
|
|
212
|
+
|
|
213
|
+
- Reduces repetitive file-handling boilerplate
|
|
214
|
+
- Beginner-friendly and easy to understand
|
|
215
|
+
- Clean and readable function names
|
|
216
|
+
- Great for small scripts and learning projects
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# ๐ Simple File Utils
|
|
2
|
+
|
|
3
|
+
A lightweight Python library for simplified file handling operations.
|
|
4
|
+
It provides easy-to-use functions for working with text, CSV, JSON, and binary files.
|
|
5
|
+
|
|
6
|
+
### โจ Features
|
|
7
|
+
|
|
8
|
+
- Read / Write / Append TXT files
|
|
9
|
+
- Read / Write / Append CSV files
|
|
10
|
+
- Read / Write JSON files
|
|
11
|
+
- Binary file support using pickle
|
|
12
|
+
- Utility helpers:
|
|
13
|
+
- `exists()`
|
|
14
|
+
- `delete()`
|
|
15
|
+
- `file_size()`
|
|
16
|
+
- `get_extension()`
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### ๐ฆ Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install simple-file-utils
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### ๐ Quickstart
|
|
28
|
+
```bash
|
|
29
|
+
import simple_file_utils as sfu
|
|
30
|
+
```
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## ๐ TXT FILE FUNCTIONS
|
|
34
|
+
|
|
35
|
+
`write_txt(file_path, data)`
|
|
36
|
+
|
|
37
|
+
Writes text to a file (overwrites if it exists).
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
sfu.write_txt("example.txt", "Hello World")
|
|
41
|
+
```
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
`read_txt(file_path)`
|
|
45
|
+
|
|
46
|
+
Reads entire file content as a string.
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
content = sfu.read_txt("example.txt")
|
|
50
|
+
print(content)
|
|
51
|
+
```
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
`readlines_txt(file_path)`
|
|
55
|
+
|
|
56
|
+
Returns file content as a list of lines.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
lines = sfu.readlines_txt("example.txt")
|
|
60
|
+
print(lines)
|
|
61
|
+
```
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
`append_txt(file_path, data)`
|
|
65
|
+
|
|
66
|
+
Appends text to an existing file.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
sfu.append_txt("example.txt", "\nNew line added")
|
|
70
|
+
```
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## ๐ CSV FILE FUNCTIONS
|
|
74
|
+
`write_csv(file_path, rows)`
|
|
75
|
+
|
|
76
|
+
Writes a list of rows to a CSV file.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
rows = [
|
|
80
|
+
["Name", "Age"],
|
|
81
|
+
["John",18]
|
|
82
|
+
]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
sfu.write_csv("data.csv", rows)
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
`read_csv(file_path)`
|
|
89
|
+
|
|
90
|
+
Reads CSV file and returns list of rows.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
data = sfu.read_csv("data.csv")
|
|
94
|
+
print(data)
|
|
95
|
+
```
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
`append_csv(file_path, rows)`
|
|
99
|
+
|
|
100
|
+
Appends rows to an existing CSV file.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
sfu.append_csv("data.csv", [["Alex", 22]])
|
|
104
|
+
```
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## ๐งพ JSON Functions
|
|
108
|
+
`write_json(file_path, data)`
|
|
109
|
+
|
|
110
|
+
Writes a dictionary or list to a JSON file.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
user = {
|
|
114
|
+
"name": "John",
|
|
115
|
+
"age": 18
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
sfu.write_json("user.json", user)
|
|
119
|
+
```
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
`read_json(file_path)`
|
|
123
|
+
|
|
124
|
+
Reads JSON file and returns Python object.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
data = sfu.read_json("user.json")
|
|
128
|
+
print(data)
|
|
129
|
+
```
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## ๐พ Binary Functions
|
|
133
|
+
`write_bin(file_path, data)`
|
|
134
|
+
|
|
135
|
+
Saves a Python object to a binary file.
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
numbers = [1, 2, 3, 4]
|
|
139
|
+
sfu.write_bin("numbers.bin", numbers)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`read_bin(file_path)`
|
|
143
|
+
|
|
144
|
+
Loads a Python object from a binary file.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
numbers = sfu.read_bin("numbers.bin")
|
|
148
|
+
print(numbers)
|
|
149
|
+
```
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## ๐ Utility Functions
|
|
153
|
+
`exists(file_path)`
|
|
154
|
+
|
|
155
|
+
Checks if file exists.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
print(sfu.exists("example.txt"))
|
|
159
|
+
```
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
`delete(file_path)`
|
|
163
|
+
|
|
164
|
+
Deletes a file.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
sfu.delete("example.txt")
|
|
168
|
+
```
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
`file_size(file_path)`
|
|
172
|
+
|
|
173
|
+
Returns file size in bytes.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
size = sfu.file_size("data.csv")
|
|
177
|
+
print(size)
|
|
178
|
+
```
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
`get_extension(file_path)`
|
|
182
|
+
|
|
183
|
+
Returns file extension in lowercase.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
print(sfu.get_extension("data.csv")) # .csv
|
|
187
|
+
```
|
|
188
|
+
---
|
|
189
|
+
## ๐ฏ Why Use This Library?
|
|
190
|
+
|
|
191
|
+
- Reduces repetitive file-handling boilerplate
|
|
192
|
+
- Beginner-friendly and easy to understand
|
|
193
|
+
- Clean and readable function names
|
|
194
|
+
- Great for small scripts and learning projects
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "simple-file-utils"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A beginner-friendly library for simplified file handling in Python."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "M R Darshan" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.8",
|
|
15
|
+
"Programming Language :: Python :: 3.9",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Topic :: Software Development :: Libraries",
|
|
23
|
+
"Topic :: Utilities",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["setuptools>=61.0"]
|
|
29
|
+
build-backend = "setuptools.build_meta"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["."]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .core import (
|
|
2
|
+
write_txt, write_bin, write_csv, write_json,
|
|
3
|
+
read_bin, read_csv, read_json, read_txt,
|
|
4
|
+
readlines_txt, append_csv, append_txt,
|
|
5
|
+
exists, delete, file_size, get_extension
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"write_txt", "write_bin", "write_csv", "write_json",
|
|
10
|
+
"read_bin", "read_csv", "read_json", "read_txt",
|
|
11
|
+
"readlines_txt", "append_csv", "append_txt",
|
|
12
|
+
"exists", "delete", "file_size", "get_extension"
|
|
13
|
+
]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import pickle
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# TXT
|
|
8
|
+
def write_txt(file_path: str, data: str):
|
|
9
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
10
|
+
f.write(data)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def read_txt(file_path: str) -> str:
|
|
14
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
15
|
+
return f.read()
|
|
16
|
+
|
|
17
|
+
def readlines_txt(file_path: str) -> list:
|
|
18
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
19
|
+
return f.readlines()
|
|
20
|
+
|
|
21
|
+
def append_txt(file_path: str, data: str):
|
|
22
|
+
with open(file_path, "a", encoding="utf-8") as f:
|
|
23
|
+
f.write(data)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# CSV
|
|
27
|
+
def write_csv(file_path: str, rows: list):
|
|
28
|
+
with open(file_path, "w", newline="", encoding="utf-8") as f:
|
|
29
|
+
writer = csv.writer(f)
|
|
30
|
+
writer.writerows(rows)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def read_csv(file_path: str):
|
|
34
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
35
|
+
reader = csv.reader(f)
|
|
36
|
+
return list(reader)
|
|
37
|
+
|
|
38
|
+
def append_csv(file_path: str, rows: list):
|
|
39
|
+
with open(file_path, "a", newline="", encoding="utf-8") as f:
|
|
40
|
+
writer = csv.writer(f)
|
|
41
|
+
writer.writerows(rows)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# BIN
|
|
45
|
+
def write_bin(file_path: str, data):
|
|
46
|
+
with open(file_path, "wb") as f:
|
|
47
|
+
pickle.dump(data, f)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def read_bin(file_path: str):
|
|
51
|
+
with open(file_path, "rb") as f:
|
|
52
|
+
return pickle.load(f)
|
|
53
|
+
|
|
54
|
+
#JSON
|
|
55
|
+
def write_json(file_path: str, data):
|
|
56
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
57
|
+
json.dump(data, f)
|
|
58
|
+
|
|
59
|
+
def read_json(file_path: str):
|
|
60
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
61
|
+
return json.load(f)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
#SOME COMMON NECESSARY FUNCTIONS
|
|
65
|
+
|
|
66
|
+
def exists(file_path: str) -> bool:
|
|
67
|
+
return os.path.exists(file_path)
|
|
68
|
+
|
|
69
|
+
def delete(file_path: str):
|
|
70
|
+
os.remove(file_path)
|
|
71
|
+
|
|
72
|
+
def file_size(file_path: str) -> int:
|
|
73
|
+
return os.path.getsize(file_path)
|
|
74
|
+
|
|
75
|
+
def get_extension(file_path: str) -> str:
|
|
76
|
+
return os.path.splitext(file_path)[1].lower()
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simple-file-utils
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A beginner-friendly library for simplified file handling in Python.
|
|
5
|
+
Author: M R Darshan
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# ๐ Simple File Utils
|
|
24
|
+
|
|
25
|
+
A lightweight Python library for simplified file handling operations.
|
|
26
|
+
It provides easy-to-use functions for working with text, CSV, JSON, and binary files.
|
|
27
|
+
|
|
28
|
+
### โจ Features
|
|
29
|
+
|
|
30
|
+
- Read / Write / Append TXT files
|
|
31
|
+
- Read / Write / Append CSV files
|
|
32
|
+
- Read / Write JSON files
|
|
33
|
+
- Binary file support using pickle
|
|
34
|
+
- Utility helpers:
|
|
35
|
+
- `exists()`
|
|
36
|
+
- `delete()`
|
|
37
|
+
- `file_size()`
|
|
38
|
+
- `get_extension()`
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### ๐ฆ Installation
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install simple-file-utils
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### ๐ Quickstart
|
|
50
|
+
```bash
|
|
51
|
+
import simple_file_utils as sfu
|
|
52
|
+
```
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## ๐ TXT FILE FUNCTIONS
|
|
56
|
+
|
|
57
|
+
`write_txt(file_path, data)`
|
|
58
|
+
|
|
59
|
+
Writes text to a file (overwrites if it exists).
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
sfu.write_txt("example.txt", "Hello World")
|
|
63
|
+
```
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
`read_txt(file_path)`
|
|
67
|
+
|
|
68
|
+
Reads entire file content as a string.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
content = sfu.read_txt("example.txt")
|
|
72
|
+
print(content)
|
|
73
|
+
```
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
`readlines_txt(file_path)`
|
|
77
|
+
|
|
78
|
+
Returns file content as a list of lines.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
lines = sfu.readlines_txt("example.txt")
|
|
82
|
+
print(lines)
|
|
83
|
+
```
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
`append_txt(file_path, data)`
|
|
87
|
+
|
|
88
|
+
Appends text to an existing file.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
sfu.append_txt("example.txt", "\nNew line added")
|
|
92
|
+
```
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## ๐ CSV FILE FUNCTIONS
|
|
96
|
+
`write_csv(file_path, rows)`
|
|
97
|
+
|
|
98
|
+
Writes a list of rows to a CSV file.
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
rows = [
|
|
102
|
+
["Name", "Age"],
|
|
103
|
+
["John",18]
|
|
104
|
+
]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
sfu.write_csv("data.csv", rows)
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
`read_csv(file_path)`
|
|
111
|
+
|
|
112
|
+
Reads CSV file and returns list of rows.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
data = sfu.read_csv("data.csv")
|
|
116
|
+
print(data)
|
|
117
|
+
```
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
`append_csv(file_path, rows)`
|
|
121
|
+
|
|
122
|
+
Appends rows to an existing CSV file.
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
sfu.append_csv("data.csv", [["Alex", 22]])
|
|
126
|
+
```
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## ๐งพ JSON Functions
|
|
130
|
+
`write_json(file_path, data)`
|
|
131
|
+
|
|
132
|
+
Writes a dictionary or list to a JSON file.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
user = {
|
|
136
|
+
"name": "John",
|
|
137
|
+
"age": 18
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
sfu.write_json("user.json", user)
|
|
141
|
+
```
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
`read_json(file_path)`
|
|
145
|
+
|
|
146
|
+
Reads JSON file and returns Python object.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
data = sfu.read_json("user.json")
|
|
150
|
+
print(data)
|
|
151
|
+
```
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## ๐พ Binary Functions
|
|
155
|
+
`write_bin(file_path, data)`
|
|
156
|
+
|
|
157
|
+
Saves a Python object to a binary file.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
numbers = [1, 2, 3, 4]
|
|
161
|
+
sfu.write_bin("numbers.bin", numbers)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`read_bin(file_path)`
|
|
165
|
+
|
|
166
|
+
Loads a Python object from a binary file.
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
numbers = sfu.read_bin("numbers.bin")
|
|
170
|
+
print(numbers)
|
|
171
|
+
```
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## ๐ Utility Functions
|
|
175
|
+
`exists(file_path)`
|
|
176
|
+
|
|
177
|
+
Checks if file exists.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
print(sfu.exists("example.txt"))
|
|
181
|
+
```
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
`delete(file_path)`
|
|
185
|
+
|
|
186
|
+
Deletes a file.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
sfu.delete("example.txt")
|
|
190
|
+
```
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
`file_size(file_path)`
|
|
194
|
+
|
|
195
|
+
Returns file size in bytes.
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
size = sfu.file_size("data.csv")
|
|
199
|
+
print(size)
|
|
200
|
+
```
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
`get_extension(file_path)`
|
|
204
|
+
|
|
205
|
+
Returns file extension in lowercase.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
print(sfu.get_extension("data.csv")) # .csv
|
|
209
|
+
```
|
|
210
|
+
---
|
|
211
|
+
## ๐ฏ Why Use This Library?
|
|
212
|
+
|
|
213
|
+
- Reduces repetitive file-handling boilerplate
|
|
214
|
+
- Beginner-friendly and easy to understand
|
|
215
|
+
- Clean and readable function names
|
|
216
|
+
- Great for small scripts and learning projects
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
simple_file_utils/__init__.py
|
|
5
|
+
simple_file_utils/core.py
|
|
6
|
+
simple_file_utils.egg-info/PKG-INFO
|
|
7
|
+
simple_file_utils.egg-info/SOURCES.txt
|
|
8
|
+
simple_file_utils.egg-info/dependency_links.txt
|
|
9
|
+
simple_file_utils.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|