simple-file-utils 0.1.0__py3-none-any.whl

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.
@@ -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,7 @@
1
+ simple_file_utils/__init__.py,sha256=-pMznJ9MyWadROXIMaJxumkY1hBKQ4q_jfA9ZGQIA58,431
2
+ simple_file_utils/core.py,sha256=8dfDnIe0mioOoCGZBA_oqMb90LJBEXCtO1B6ZEv-0bk,1825
3
+ simple_file_utils-0.1.0.dist-info/licenses/LICENSE,sha256=RrxW6AmDCskP0BLiPoDUDI8ZD9qB6NZ20zFaVF7tkDA,1068
4
+ simple_file_utils-0.1.0.dist-info/METADATA,sha256=YTxcADEQIBBt07u_fwxDMkahAxsWsl5JZ_-CnDjmMDM,3685
5
+ simple_file_utils-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ simple_file_utils-0.1.0.dist-info/top_level.txt,sha256=57Z5cr12q9hWK1XwSCpSbTJcvFxWyp_9rzL-JH4CEZs,18
7
+ simple_file_utils-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -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 @@
1
+ simple_file_utils