dbpush 1.0.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.
- dbpush-1.0.0/PKG-INFO +455 -0
- dbpush-1.0.0/README.md +436 -0
- dbpush-1.0.0/dbpush/__init__.py +1 -0
- dbpush-1.0.0/dbpush/cli.py +294 -0
- dbpush-1.0.0/dbpush/dbpush.py +465 -0
- dbpush-1.0.0/dbpush/editor.py +197 -0
- dbpush-1.0.0/dbpush/os_sys.py +60 -0
- dbpush-1.0.0/dbpush.egg-info/PKG-INFO +455 -0
- dbpush-1.0.0/dbpush.egg-info/SOURCES.txt +14 -0
- dbpush-1.0.0/dbpush.egg-info/dependency_links.txt +1 -0
- dbpush-1.0.0/dbpush.egg-info/entry_points.txt +2 -0
- dbpush-1.0.0/dbpush.egg-info/requires.txt +4 -0
- dbpush-1.0.0/dbpush.egg-info/top_level.txt +1 -0
- dbpush-1.0.0/pyproject.toml +24 -0
- dbpush-1.0.0/setup.cfg +4 -0
- dbpush-1.0.0/setup.py +33 -0
dbpush-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbpush
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Import Excel / CSV files directly into MySQL or PostgreSQL from the terminal
|
|
5
|
+
Home-page: https://github.com/RangamRKSS/dbpush
|
|
6
|
+
Author: Sarthak sachdeva
|
|
7
|
+
Author-email: Sarthak sachdeva <rangamapp@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/RangamRKSS/dbpush
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg[binary]>=3.0
|
|
13
|
+
Requires-Dist: mysql-connector-python>=8.0
|
|
14
|
+
Requires-Dist: openpyxl>=3.0
|
|
15
|
+
Requires-Dist: rich>=13.0
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: home-page
|
|
18
|
+
Dynamic: requires-python
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
|
|
22
|
+
<br/>
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
██████╗ ██████╗ ██████╗ ██╗ ██╗███████╗██╗ ██╗
|
|
26
|
+
██╔══██╗██╔══██╗██╔══██╗██║ ██║██╔════╝██║ ██║
|
|
27
|
+
██║ ██║██████╔╝██████╔╝██║ ██║███████╗███████║
|
|
28
|
+
██║ ██║██╔══██╗██╔═══╝ ██║ ██║╚════██║██╔══██║
|
|
29
|
+
██████╔╝██████╔╝██║ ╚██████╔╝███████║██║ ██║
|
|
30
|
+
╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Import `.csv` and `.xlsx` files directly into PostgreSQL and MySQL
|
|
34
|
+
### — from your terminal or Python code.
|
|
35
|
+
|
|
36
|
+
<br/>
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/dbpush/1.0.0/)
|
|
39
|
+
[](https://python.org)
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
[]()
|
|
42
|
+
[]()
|
|
43
|
+
|
|
44
|
+
<br/>
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## What is DBSHEET?
|
|
51
|
+
|
|
52
|
+
DBSHEET is a **zero-boilerplate** CLI and Python utility that turns spreadsheet files into live database tables. No schema writing. No manual column mapping. No encoding headaches.
|
|
53
|
+
|
|
54
|
+
> Point it at a file. Configure the database. Done.
|
|
55
|
+
how to use cli tool
|
|
56
|
+
|
|
57
|
+
python -m dbpush.cli
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## The Old Way vs DBSHEET
|
|
61
|
+
|
|
62
|
+
| Without DBSHEET | With DBSHEET |
|
|
63
|
+
|---|---|
|
|
64
|
+
| Open spreadsheet | `pip install dbpush==1.0.0` |
|
|
65
|
+
| Write a custom parser | `dbpush` (or 3 lines of Python) |
|
|
66
|
+
| Map columns manually | ✅ Auto schema from headers |
|
|
67
|
+
| Write SQL CREATE TABLE | ✅ Table created automatically |
|
|
68
|
+
| Write INSERT loops | ✅ Rows inserted + upserted |
|
|
69
|
+
| Debug encoding issues | ✅ Just works |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
✦ CSV import ✦ Excel (.xlsx) import
|
|
77
|
+
✦ PostgreSQL support ✦ MySQL support
|
|
78
|
+
✦ Auto table creation ✦ Header-based schema generation
|
|
79
|
+
✦ Upsert on duplicate keys ✦ Interactive CLI
|
|
80
|
+
✦ Python API ✦ Config file support
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install dbpush
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Quick Start
|
|
94
|
+
|
|
95
|
+
### Config File
|
|
96
|
+
|
|
97
|
+
Create a `config.txt` file:
|
|
98
|
+
|
|
99
|
+
```txt
|
|
100
|
+
db_type:postgres
|
|
101
|
+
host:localhost
|
|
102
|
+
port:5432
|
|
103
|
+
user:postgres
|
|
104
|
+
password:secret
|
|
105
|
+
database:mydb
|
|
106
|
+
file_name:./data.csv
|
|
107
|
+
sheet_name:Sheet1
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### CLI
|
|
113
|
+
|
|
114
|
+
Launch the interactive terminal:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
dbsheet
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Typical workflow:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
config_file # load your config
|
|
124
|
+
connect # connect to the database
|
|
125
|
+
create_table # create table from spreadsheet headers
|
|
126
|
+
insert # insert all rows
|
|
127
|
+
select # view the data
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### Python API
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from dbpush.dbpush import Dbpush
|
|
136
|
+
|
|
137
|
+
db = Dbpush.create(
|
|
138
|
+
db_type="postgres",
|
|
139
|
+
host="localhost",
|
|
140
|
+
user="postgres",
|
|
141
|
+
password="secret",
|
|
142
|
+
database="mydb",
|
|
143
|
+
port=5432,
|
|
144
|
+
file_name="./data.csv"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
db.connect()
|
|
148
|
+
db.create_table()
|
|
149
|
+
db.insert()
|
|
150
|
+
db.select_all()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Supported Formats
|
|
156
|
+
|
|
157
|
+
| File Type | Supported |
|
|
158
|
+
|-----------|-----------|
|
|
159
|
+
| `.csv` | ✅ Yes |
|
|
160
|
+
| `.xlsx` | ✅ Yes |
|
|
161
|
+
|
|
162
|
+
## Supported Databases
|
|
163
|
+
|
|
164
|
+
| Database | Supported |
|
|
165
|
+
|------------|-----------|
|
|
166
|
+
| PostgreSQL | ✅ Yes |
|
|
167
|
+
| MySQL | ✅ Yes |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Example Input
|
|
172
|
+
|
|
173
|
+
**CSV:**
|
|
174
|
+
```csv
|
|
175
|
+
id,name,age,salary
|
|
176
|
+
1,ram,22,50000
|
|
177
|
+
2,radha,25,70000
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
DBSHEET will:
|
|
181
|
+
- Create a table named `data`
|
|
182
|
+
- Map each header to a column (`id` → primary key, rest → text)
|
|
183
|
+
- Insert all rows automatically
|
|
184
|
+
- Upsert if a row with the same primary key already exists
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## CLI Commands
|
|
189
|
+
|
|
190
|
+
| Command | Description |
|
|
191
|
+
|----------------|--------------------------------------------------|
|
|
192
|
+
| `config` | Configure database connection manually |
|
|
193
|
+
| `config_file` | Load configuration from a file |
|
|
194
|
+
| `connect` | Connect to the database |
|
|
195
|
+
| `create_db` | Create the database if it doesn't exist |
|
|
196
|
+
| `create_table` | Create a table from the spreadsheet headers |
|
|
197
|
+
| `insert` | Insert (or upsert) all rows from the file |
|
|
198
|
+
| `select` | Display all rows from the table |
|
|
199
|
+
| `truncate` | Remove all rows from the table (keep structure) |
|
|
200
|
+
| `drop_table` | Permanently delete the table |
|
|
201
|
+
| `row_count` | Print the number of rows in the spreadsheet |
|
|
202
|
+
| `col_count` | Print the number of columns in the spreadsheet |
|
|
203
|
+
| `header` | Display column names from the spreadsheet |
|
|
204
|
+
| `sheet` | Display the active sheet name |
|
|
205
|
+
| `find` | Search for a row by column value |
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Python API Reference
|
|
210
|
+
|
|
211
|
+
### `Dbpush.create(...)`
|
|
212
|
+
|
|
213
|
+
Factory method to create a new Dbsheet instance.
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
db = Dbpush.create(
|
|
217
|
+
db_type="postgres", # "postgres" or "mysql"
|
|
218
|
+
host="localhost",
|
|
219
|
+
user="postgres",
|
|
220
|
+
password="secret",
|
|
221
|
+
database="mydb",
|
|
222
|
+
port=5432,
|
|
223
|
+
file_name="./data.csv",
|
|
224
|
+
sheet_name="Sheet1" # optional, for .xlsx files
|
|
225
|
+
)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
### `create_db()`
|
|
231
|
+
|
|
232
|
+
Creates the database if it does not already exist.
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
db.create_db()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
### `connect()`
|
|
241
|
+
|
|
242
|
+
Establishes a connection to the database and prepares the cursor.
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
db.connect()
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### `create_table()`
|
|
251
|
+
|
|
252
|
+
Reads the spreadsheet headers and creates a matching SQL table.
|
|
253
|
+
|
|
254
|
+
- The `id` column is set as the **primary key**
|
|
255
|
+
- All other columns are created as **text** fields
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
db.create_table()
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### `insert()`
|
|
264
|
+
|
|
265
|
+
Reads all rows from the spreadsheet and inserts them into the table.
|
|
266
|
+
|
|
267
|
+
Handles duplicate primary keys via **upsert** — existing rows are updated, new rows are inserted.
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
db.insert()
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### `select_all()`
|
|
276
|
+
|
|
277
|
+
Prints all rows currently in the table.
|
|
278
|
+
|
|
279
|
+
```python
|
|
280
|
+
db.select_all()
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
### `drop_table()`
|
|
286
|
+
|
|
287
|
+
Permanently deletes the table from the database.
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
db.drop_table()
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
### `truncate_table()`
|
|
296
|
+
|
|
297
|
+
Removes all rows from the table while keeping the table structure intact.
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
db.truncate_table()
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
### `row_count()`
|
|
306
|
+
|
|
307
|
+
Prints the total number of data rows in the spreadsheet (excluding the header).
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
db.row_count()
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
### `col_count()`
|
|
316
|
+
|
|
317
|
+
Prints the total number of columns in the spreadsheet.
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
db.col_count()
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
### `show_header()`
|
|
326
|
+
|
|
327
|
+
Prints the list of column names from the spreadsheet header row.
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
db.show_header()
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
### `show_sheet()`
|
|
336
|
+
|
|
337
|
+
Prints the name of the active sheet (relevant for `.xlsx` files).
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
db.show_sheet()
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### `find(column, value)`
|
|
346
|
+
|
|
347
|
+
Searches through the spreadsheet rows and returns rows where `column` matches `value`.
|
|
348
|
+
|
|
349
|
+
```python
|
|
350
|
+
db.find("name", "ram")
|
|
351
|
+
# Returns all rows where the "name" column equals "ram"
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Full Examples
|
|
357
|
+
|
|
358
|
+
### PostgreSQL
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
from dbpush.dbpush import Dbpush
|
|
362
|
+
|
|
363
|
+
db = Dbpush.create(
|
|
364
|
+
db_type="postgres",
|
|
365
|
+
host="localhost",
|
|
366
|
+
user="postgres",
|
|
367
|
+
password="secret",
|
|
368
|
+
database="mydb",
|
|
369
|
+
port=5432,
|
|
370
|
+
file_name="./data.csv"
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
db.connect()
|
|
374
|
+
db.create_table()
|
|
375
|
+
db.insert()
|
|
376
|
+
db.select_all()
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### MySQL
|
|
380
|
+
|
|
381
|
+
```python
|
|
382
|
+
from dbpush.dbpush import Dbpush
|
|
383
|
+
|
|
384
|
+
db = Dbpush.create(
|
|
385
|
+
db_type="mysql",
|
|
386
|
+
host="localhost",
|
|
387
|
+
user="root",
|
|
388
|
+
password="secret",
|
|
389
|
+
database="mydb",
|
|
390
|
+
port=3306,
|
|
391
|
+
file_name="./data.xlsx",
|
|
392
|
+
sheet_name="Sheet1"
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
db.connect()
|
|
396
|
+
db.create_table()
|
|
397
|
+
db.insert()
|
|
398
|
+
db.select_all()
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## Use Cases
|
|
404
|
+
|
|
405
|
+
- 🌱 Seeding development and staging databases
|
|
406
|
+
- 🛠 Internal admin tools and dashboards
|
|
407
|
+
- ⚡ Rapid prototyping with real data
|
|
408
|
+
- 📦 Importing spreadsheets from clients
|
|
409
|
+
- 🔄 Lightweight ETL pipelines
|
|
410
|
+
- 📊 Data migration scripts
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## Project Structure
|
|
415
|
+
|
|
416
|
+
```
|
|
417
|
+
dbsheet-public/
|
|
418
|
+
├── README.md
|
|
419
|
+
├── examples/
|
|
420
|
+
│ ├── postgres_example.py
|
|
421
|
+
│ └── mysql_example.py
|
|
422
|
+
├── screenshots/
|
|
423
|
+
│ ├── cli.png
|
|
424
|
+
│ └── demo.gif
|
|
425
|
+
└── roadmap.md
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## Roadmap
|
|
431
|
+
|
|
432
|
+
- [ ] Better type inference (int, float, date detection)
|
|
433
|
+
- [ ] Connection URI support (`postgresql://user:pass@host/db`)
|
|
434
|
+
- [ ] Batch folder import (import entire directory of files)
|
|
435
|
+
- [ ] Improved error messages and validation
|
|
436
|
+
- [ ] Export database table → CSV
|
|
437
|
+
- [ ] SQLite support
|
|
438
|
+
|
|
439
|
+
See [`roadmap.md`](roadmap.md) for full details.
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## License
|
|
444
|
+
|
|
445
|
+
MIT © [Sarthak sachdeva](https://github.com/RangamRKSS)
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
<div align="center">
|
|
450
|
+
|
|
451
|
+
**If dbpush saved you time, a ⭐ on the repo means a lot.**
|
|
452
|
+
|
|
453
|
+
Built with ♥ by **Sarthak sachdeva**
|
|
454
|
+
|
|
455
|
+
</div>
|