sql2csv 1.2__tar.gz → 1.4__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.
sql2csv-1.4/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Gabriel Bordeaux
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.
sql2csv-1.4/PKG-INFO ADDED
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: sql2csv
3
+ Version: 1.4
4
+ Summary: Run MySQL and PostgreSQL queries and store result in CSV
5
+ Author-email: Gabriel Bordeaux <pypi@gab.lc>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/gabfl/sql2csv
8
+ Classifier: Topic :: Database
9
+ Classifier: Topic :: Database :: Database Engines/Servers
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Development Status :: 4 - Beta
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: PyMySQL>=1.1
26
+ Requires-Dist: psycopg2-binary>=2.9.10
27
+ Dynamic: license-file
28
+
29
+ # sql2csv
30
+
31
+ [![Pypi](https://img.shields.io/pypi/v/sql2csv.svg)](https://pypi.org/project/sql2csv)
32
+ [![Build Status](https://github.com/gabfl/sql2csv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gabfl/sql2csv/actions)
33
+ [![codecov](https://codecov.io/gh/gabfl/sql2csv/branch/main/graph/badge.svg)](https://codecov.io/gh/gabfl/sql2csv)
34
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/sql2csv/main/LICENSE)
35
+
36
+ Run MySQL and PostgreSQL queries and store the results in CSV.
37
+
38
+ ## Why sql2csv
39
+
40
+ `sql2csv` is a small utility to run MySQL and PostgreSQL queries and store the output in a CSV file.
41
+
42
+ In some environments like when using MySQL or Aurora in AWS RDS, exporting queries' results to CSV is not available with native tools. `sql2csv` is a simple module that offers this feature.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip3 install sql2csv
48
+
49
+ # Basic usage
50
+ mysql [...] -e "SELECT * FROM table" | sql2csv
51
+ # or
52
+ psql [...] -c "SELECT * FROM table" | sql2csv
53
+ ```
54
+
55
+ ## Example
56
+
57
+ ### From stdin
58
+
59
+ For simple queries you can pipe a result directly from `mysql` or `psql` to `sql2csv`.
60
+
61
+ For more complex queries, it is recommended to use the CLI (see below) to ensure a properly formatted CSV.
62
+
63
+ ```bash
64
+ mysql -U root -p"secret" my_db -e "SELECT * FROM some_mysql_table;" | sql2csv
65
+
66
+ id,some_int,some_str,some_date
67
+ 1,12,hello world,2018-12-01 12:23:12
68
+ 2,15,hello,2018-12-05 12:18:12
69
+ 3,18,world,2018-12-08 12:17:12
70
+ ```
71
+
72
+ ```bash
73
+ psql -U postgres my_db -c "SELECT * FROM some_pg_table" | sql2csv
74
+
75
+ id,some_int,some_str,some_date
76
+ 1,12,hello world,2018-12-01 12:23:12
77
+ 2,15,hello,2018-12-05 12:18:12
78
+ 3,18,world,2018-12-08 12:17:12
79
+ ```
80
+
81
+ ### Using `sql2csv` CLI
82
+
83
+ #### Output to stdout
84
+
85
+ ```bash
86
+ $ sql2csv --engine mysql \
87
+ --database my_db --user root --password "secret" \
88
+ --query "SELECT * FROM some_mysql_table"
89
+
90
+ 1,12,hello world,2018-12-01 12:23:12
91
+ 2,15,hello,2018-12-05 12:18:12
92
+ 3,18,world,2018-12-08 12:17:12
93
+ ```
94
+
95
+ #### Output saved in a file
96
+
97
+ ```bash
98
+ $ sql2csv --engine mysql \
99
+ --database my_db --user root --password "secret" \
100
+ --query "SELECT * FROM some_mysql_table" \
101
+ --headers \
102
+ --out file --destination_file export.csv
103
+
104
+ # * Exporting rows...
105
+ # ...done
106
+ # * The result has been exported to export.csv.
107
+
108
+ $ cat export.csv
109
+ id,some_int,some_str,some_date
110
+ 1,12,hello world,2018-12-01 12:23:12
111
+ 2,15,hello,2018-12-05 12:18:12
112
+ 3,18,world,2018-12-08 12:17:12
113
+ ```
114
+
115
+ ## Usage
116
+
117
+ ```bash
118
+ usage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER
119
+ [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]
120
+ [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR] [-t]
121
+
122
+ optional arguments:
123
+ -h, --help show this help message and exit
124
+ -e {mysql,postgresql}, --engine {mysql,postgresql}
125
+ Database engine
126
+ -H HOST, --host HOST Database host
127
+ -P PORT, --port PORT Database port
128
+ -u USER, --user USER Database user
129
+ -p PASSWORD, --password PASSWORD
130
+ Database password
131
+ -d DATABASE, --database DATABASE
132
+ Database name
133
+ -q QUERY, --query QUERY
134
+ SQL query
135
+ -o {stdout,file}, --out {stdout,file}
136
+ CSV destination
137
+ -f DESTINATION_FILE, --destination_file DESTINATION_FILE
138
+ CSV destination file
139
+ -D DELIMITER, --delimiter DELIMITER
140
+ CSV delimiter
141
+ -Q QUOTECHAR, --quotechar QUOTECHAR
142
+ CSV quote character
143
+ -t, --headers Include headers
144
+ ```
@@ -1,9 +1,9 @@
1
1
  # sql2csv
2
2
 
3
3
  [![Pypi](https://img.shields.io/pypi/v/sql2csv.svg)](https://pypi.org/project/sql2csv)
4
- [![Build Status](https://travis-ci.org/gabfl/sql2csv.svg?branch=master)](https://travis-ci.org/gabfl/sql2csv)
5
- [![codecov](https://codecov.io/gh/gabfl/sql2csv/branch/master/graph/badge.svg)](https://codecov.io/gh/gabfl/sql2csv)
6
- [![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/sql2csv/master/LICENSE)
4
+ [![Build Status](https://github.com/gabfl/sql2csv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gabfl/sql2csv/actions)
5
+ [![codecov](https://codecov.io/gh/gabfl/sql2csv/branch/main/graph/badge.svg)](https://codecov.io/gh/gabfl/sql2csv)
6
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/sql2csv/main/LICENSE)
7
7
 
8
8
  Run MySQL and PostgreSQL queries and store the results in CSV.
9
9
 
@@ -70,6 +70,7 @@ $ sql2csv --engine mysql \
70
70
  $ sql2csv --engine mysql \
71
71
  --database my_db --user root --password "secret" \
72
72
  --query "SELECT * FROM some_mysql_table" \
73
+ --headers \
73
74
  --out file --destination_file export.csv
74
75
 
75
76
  # * Exporting rows...
@@ -77,6 +78,7 @@ $ sql2csv --engine mysql \
77
78
  # * The result has been exported to export.csv.
78
79
 
79
80
  $ cat export.csv
81
+ id,some_int,some_str,some_date
80
82
  1,12,hello world,2018-12-01 12:23:12
81
83
  2,15,hello,2018-12-05 12:18:12
82
84
  3,18,world,2018-12-08 12:17:12
@@ -87,7 +89,7 @@ $ cat export.csv
87
89
  ```bash
88
90
  usage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER
89
91
  [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]
90
- [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR]
92
+ [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR] [-t]
91
93
 
92
94
  optional arguments:
93
95
  -h, --help show this help message and exit
@@ -110,4 +112,5 @@ optional arguments:
110
112
  CSV delimiter
111
113
  -Q QUOTECHAR, --quotechar QUOTECHAR
112
114
  CSV quote character
113
- ```
115
+ -t, --headers Include headers
116
+ ```
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sql2csv"
7
+ version = "1.4"
8
+ description = "Run MySQL and PostgreSQL queries and store result in CSV"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Gabriel Bordeaux", email = "pypi@gab.lc" }]
13
+ requires-python = ">=3.10"
14
+ dependencies = [
15
+ "PyMySQL>=1.1",
16
+ "psycopg2-binary>=2.9.10",
17
+ ]
18
+ classifiers = [
19
+ "Topic :: Database",
20
+ "Topic :: Database :: Database Engines/Servers",
21
+ "Operating System :: MacOS",
22
+ "Operating System :: POSIX :: Linux",
23
+ "Natural Language :: English",
24
+ "Programming Language :: Python",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Programming Language :: Python :: 3.14",
32
+ "Development Status :: 4 - Beta",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/gabfl/sql2csv"
37
+
38
+ [project.scripts]
39
+ sql2csv = "sql2csv.sql2csv:main"
40
+
41
+ [tool.setuptools]
42
+ packages = ["sql2csv"]
43
+ package-dir = { "sql2csv" = "src" }
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: sql2csv
3
+ Version: 1.4
4
+ Summary: Run MySQL and PostgreSQL queries and store result in CSV
5
+ Author-email: Gabriel Bordeaux <pypi@gab.lc>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/gabfl/sql2csv
8
+ Classifier: Topic :: Database
9
+ Classifier: Topic :: Database :: Database Engines/Servers
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Development Status :: 4 - Beta
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: PyMySQL>=1.1
26
+ Requires-Dist: psycopg2-binary>=2.9.10
27
+ Dynamic: license-file
28
+
29
+ # sql2csv
30
+
31
+ [![Pypi](https://img.shields.io/pypi/v/sql2csv.svg)](https://pypi.org/project/sql2csv)
32
+ [![Build Status](https://github.com/gabfl/sql2csv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gabfl/sql2csv/actions)
33
+ [![codecov](https://codecov.io/gh/gabfl/sql2csv/branch/main/graph/badge.svg)](https://codecov.io/gh/gabfl/sql2csv)
34
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/sql2csv/main/LICENSE)
35
+
36
+ Run MySQL and PostgreSQL queries and store the results in CSV.
37
+
38
+ ## Why sql2csv
39
+
40
+ `sql2csv` is a small utility to run MySQL and PostgreSQL queries and store the output in a CSV file.
41
+
42
+ In some environments like when using MySQL or Aurora in AWS RDS, exporting queries' results to CSV is not available with native tools. `sql2csv` is a simple module that offers this feature.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip3 install sql2csv
48
+
49
+ # Basic usage
50
+ mysql [...] -e "SELECT * FROM table" | sql2csv
51
+ # or
52
+ psql [...] -c "SELECT * FROM table" | sql2csv
53
+ ```
54
+
55
+ ## Example
56
+
57
+ ### From stdin
58
+
59
+ For simple queries you can pipe a result directly from `mysql` or `psql` to `sql2csv`.
60
+
61
+ For more complex queries, it is recommended to use the CLI (see below) to ensure a properly formatted CSV.
62
+
63
+ ```bash
64
+ mysql -U root -p"secret" my_db -e "SELECT * FROM some_mysql_table;" | sql2csv
65
+
66
+ id,some_int,some_str,some_date
67
+ 1,12,hello world,2018-12-01 12:23:12
68
+ 2,15,hello,2018-12-05 12:18:12
69
+ 3,18,world,2018-12-08 12:17:12
70
+ ```
71
+
72
+ ```bash
73
+ psql -U postgres my_db -c "SELECT * FROM some_pg_table" | sql2csv
74
+
75
+ id,some_int,some_str,some_date
76
+ 1,12,hello world,2018-12-01 12:23:12
77
+ 2,15,hello,2018-12-05 12:18:12
78
+ 3,18,world,2018-12-08 12:17:12
79
+ ```
80
+
81
+ ### Using `sql2csv` CLI
82
+
83
+ #### Output to stdout
84
+
85
+ ```bash
86
+ $ sql2csv --engine mysql \
87
+ --database my_db --user root --password "secret" \
88
+ --query "SELECT * FROM some_mysql_table"
89
+
90
+ 1,12,hello world,2018-12-01 12:23:12
91
+ 2,15,hello,2018-12-05 12:18:12
92
+ 3,18,world,2018-12-08 12:17:12
93
+ ```
94
+
95
+ #### Output saved in a file
96
+
97
+ ```bash
98
+ $ sql2csv --engine mysql \
99
+ --database my_db --user root --password "secret" \
100
+ --query "SELECT * FROM some_mysql_table" \
101
+ --headers \
102
+ --out file --destination_file export.csv
103
+
104
+ # * Exporting rows...
105
+ # ...done
106
+ # * The result has been exported to export.csv.
107
+
108
+ $ cat export.csv
109
+ id,some_int,some_str,some_date
110
+ 1,12,hello world,2018-12-01 12:23:12
111
+ 2,15,hello,2018-12-05 12:18:12
112
+ 3,18,world,2018-12-08 12:17:12
113
+ ```
114
+
115
+ ## Usage
116
+
117
+ ```bash
118
+ usage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER
119
+ [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]
120
+ [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR] [-t]
121
+
122
+ optional arguments:
123
+ -h, --help show this help message and exit
124
+ -e {mysql,postgresql}, --engine {mysql,postgresql}
125
+ Database engine
126
+ -H HOST, --host HOST Database host
127
+ -P PORT, --port PORT Database port
128
+ -u USER, --user USER Database user
129
+ -p PASSWORD, --password PASSWORD
130
+ Database password
131
+ -d DATABASE, --database DATABASE
132
+ Database name
133
+ -q QUERY, --query QUERY
134
+ SQL query
135
+ -o {stdout,file}, --out {stdout,file}
136
+ CSV destination
137
+ -f DESTINATION_FILE, --destination_file DESTINATION_FILE
138
+ CSV destination file
139
+ -D DELIMITER, --delimiter DELIMITER
140
+ CSV delimiter
141
+ -Q QUOTECHAR, --quotechar QUOTECHAR
142
+ CSV quote character
143
+ -t, --headers Include headers
144
+ ```
@@ -1,5 +1,6 @@
1
+ LICENSE
1
2
  README.md
2
- setup.py
3
+ pyproject.toml
3
4
  sql2csv.egg-info/PKG-INFO
4
5
  sql2csv.egg-info/SOURCES.txt
5
6
  sql2csv.egg-info/dependency_links.txt
@@ -1,3 +1,2 @@
1
1
  [console_scripts]
2
2
  sql2csv = sql2csv.sql2csv:main
3
-
@@ -0,0 +1,2 @@
1
+ PyMySQL>=1.1
2
+ psycopg2-binary>=2.9.10
@@ -3,7 +3,9 @@
3
3
  import sys
4
4
  import csv
5
5
  import tempfile
6
+ import os
6
7
  from os.path import expanduser
8
+ import json
7
9
 
8
10
  import argparse
9
11
  import pymysql.cursors
@@ -15,24 +17,20 @@ file_ = None
15
17
 
16
18
 
17
19
  def get_mysql_connection(host, user, port, password, database):
18
- """
19
- MySQL connection
20
- """
20
+ """ MySQL connection """
21
21
 
22
22
  return pymysql.connect(host=host,
23
23
  user=user,
24
24
  port=port,
25
25
  password=password,
26
- db=database,
26
+ database=database,
27
27
  charset='utf8mb4',
28
28
  client_flag=pymysql.constants.CLIENT.MULTI_STATEMENTS
29
29
  )
30
30
 
31
31
 
32
32
  def get_pg_connection(host, user, port, password, database):
33
- """
34
- PostgreSQL connection
35
- """
33
+ """ PostgreSQL connection """
36
34
 
37
35
  return psycopg2.connect(host=host,
38
36
  user=user,
@@ -43,9 +41,7 @@ def get_pg_connection(host, user, port, password, database):
43
41
 
44
42
 
45
43
  def get_connection(engine, host, user, port, password, database):
46
- """
47
- Get SQL connection
48
- """
44
+ """ Get SQL connection """
49
45
 
50
46
  if engine == 'mysql':
51
47
  return get_mysql_connection(host, user, port, password, database)
@@ -57,9 +53,7 @@ def get_connection(engine, host, user, port, password, database):
57
53
 
58
54
 
59
55
  def get_cursor(connection):
60
- """
61
- Return connection cursor
62
- """
56
+ """ Return connection cursor """
63
57
 
64
58
  return connection.cursor()
65
59
 
@@ -84,7 +78,7 @@ def fetch_headers(cursor):
84
78
 
85
79
 
86
80
  def discard_line(line):
87
- """ Decide whether we should keep or dicard a line """
81
+ """ Decide whether we should keep or discard a line """
88
82
 
89
83
  if line[:1] in ['', '+', '(', '-']:
90
84
  return True
@@ -120,6 +114,17 @@ def strip_whitespaces(tpl):
120
114
  return [item.strip() for item in tpl]
121
115
 
122
116
 
117
+ def stringify_items(row):
118
+ """ Loop thru each item and Json-encode dicts """
119
+
120
+ row = list(row)
121
+ for k, item in enumerate(row):
122
+ if (isinstance(item, dict)):
123
+ row[k] = json.dumps(item)
124
+
125
+ return tuple(row)
126
+
127
+
123
128
  def has_stdin_input():
124
129
  """ Return `True` if there is an stdin input """
125
130
 
@@ -169,12 +174,16 @@ def get_writer(file_, delimiter=',', quotechar='"'):
169
174
  )
170
175
 
171
176
 
172
- def file_to_stdout():
177
+ def file_to_stdout(remove=False):
173
178
  """ Print file content to stdout """
174
179
 
175
180
  with open(file_.name) as f:
176
181
  print(f.read())
177
182
 
183
+ # Remove the temporary file once it has been printed
184
+ if remove:
185
+ os.remove(file_.name)
186
+
178
187
 
179
188
  def stdin_to_csv(delimiter=',', quotechar='"'):
180
189
  """ Parse stdin and return output in a CSV format """
@@ -186,8 +195,6 @@ def stdin_to_csv(delimiter=',', quotechar='"'):
186
195
  # Parse lines and add to file
187
196
  separator = None
188
197
  for line in sys.stdin:
189
- # Strip whitespaces
190
- line.strip()
191
198
 
192
199
  if not discard_line(line):
193
200
  # Get column separator
@@ -207,7 +214,7 @@ def stdin_to_csv(delimiter=',', quotechar='"'):
207
214
  # Write row
208
215
  writer.writerow(row)
209
216
 
210
- file_to_stdout()
217
+ file_to_stdout(remove=True)
211
218
 
212
219
 
213
220
  def query_to_csv(engine, host, user, port, password, database, query, headers=False, out_type='stdout', destination_file=None, delimiter=',', quotechar='"', print_info=1000):
@@ -246,6 +253,8 @@ def query_to_csv(engine, host, user, port, password, database, query, headers=Fa
246
253
  if out_type == 'file' and i % print_info == 0:
247
254
  print(' ...%s rows written' % "{:,}".format(i))
248
255
 
256
+ row = stringify_items(row)
257
+
249
258
  writer.writerow(row)
250
259
 
251
260
  if out_type == 'file':
@@ -255,7 +264,7 @@ def query_to_csv(engine, host, user, port, password, database, query, headers=Fa
255
264
 
256
265
  # Print stdout
257
266
  if out_type == 'stdout':
258
- file_to_stdout()
267
+ file_to_stdout(remove=True)
259
268
 
260
269
 
261
270
  def main():
sql2csv-1.2/PKG-INFO DELETED
@@ -1,152 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: sql2csv
3
- Version: 1.2
4
- Summary: Run MySQL and PostgreSQL queries and store result in CSV
5
- Home-page: https://github.com/gabfl/sql2csv
6
- Author: Gabriel Bordeaux
7
- Author-email: pypi@gab.lc
8
- License: MIT
9
- Description: sql2csv
10
- =======
11
-
12
- |Pypi| |Build Status| |codecov| |MIT licensed|
13
-
14
- Run MySQL and PostgreSQL queries and store the results in CSV.
15
-
16
- Why sql2csv
17
- -----------
18
-
19
- ``sql2csv`` is a small utility to run MySQL and PostgreSQL queries and
20
- store the output in a CSV file.
21
-
22
- In some environments like when using MySQL or Aurora in AWS RDS,
23
- exporting queries’ results to CSV is not available with native tools.
24
- ``sql2csv`` is a simple module that offers this feature.
25
-
26
- Installation
27
- ------------
28
-
29
- .. code:: bash
30
-
31
- pip3 install sql2csv
32
-
33
- # Basic usage
34
- mysql [...] -e "SELECT * FROM table" | sql2csv
35
- # or
36
- psql [...] -c "SELECT * FROM table" | sql2csv
37
-
38
- Example
39
- -------
40
-
41
- From stdin
42
- ~~~~~~~~~~
43
-
44
- For simple queries you can pipe a result directly from ``mysql`` or
45
- ``psql`` to ``sql2csv``.
46
-
47
- For more complex queries, it is recommended to use the CLI (see below)
48
- to ensure a properly formatted CSV.
49
-
50
- .. code:: bash
51
-
52
- mysql -U root -p"secret" my_db -e "SELECT * FROM some_mysql_table;" | sql2csv
53
-
54
- id,some_int,some_str,some_date
55
- 1,12,hello world,2018-12-01 12:23:12
56
- 2,15,hello,2018-12-05 12:18:12
57
- 3,18,world,2018-12-08 12:17:12
58
-
59
- .. code:: bash
60
-
61
- psql -U postgres my_db -c "SELECT * FROM some_pg_table" | sql2csv
62
-
63
- id,some_int,some_str,some_date
64
- 1,12,hello world,2018-12-01 12:23:12
65
- 2,15,hello,2018-12-05 12:18:12
66
- 3,18,world,2018-12-08 12:17:12
67
-
68
- Using ``sql2csv`` CLI
69
- ~~~~~~~~~~~~~~~~~~~~~
70
-
71
- Output to stdout
72
- ^^^^^^^^^^^^^^^^
73
-
74
- .. code:: bash
75
-
76
- $ sql2csv --engine mysql \
77
- --database my_db --user root --password "secret" \
78
- --query "SELECT * FROM some_mysql_table"
79
-
80
- 1,12,hello world,2018-12-01 12:23:12
81
- 2,15,hello,2018-12-05 12:18:12
82
- 3,18,world,2018-12-08 12:17:12
83
-
84
- Output saved in a file
85
- ^^^^^^^^^^^^^^^^^^^^^^
86
-
87
- .. code:: bash
88
-
89
- $ sql2csv --engine mysql \
90
- --database my_db --user root --password "secret" \
91
- --query "SELECT * FROM some_mysql_table" \
92
- --out file --destination_file export.csv
93
-
94
- # * Exporting rows...
95
- # ...done
96
- # * The result has been exported to export.csv.
97
-
98
- $ cat export.csv
99
- 1,12,hello world,2018-12-01 12:23:12
100
- 2,15,hello,2018-12-05 12:18:12
101
- 3,18,world,2018-12-08 12:17:12
102
-
103
- Usage
104
- -----
105
-
106
- .. code:: bash
107
-
108
- usage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER
109
- [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]
110
- [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR]
111
-
112
- optional arguments:
113
- -h, --help show this help message and exit
114
- -e {mysql,postgresql}, --engine {mysql,postgresql}
115
- Database engine
116
- -H HOST, --host HOST Database host
117
- -P PORT, --port PORT Database port
118
- -u USER, --user USER Database user
119
- -p PASSWORD, --password PASSWORD
120
- Database password
121
- -d DATABASE, --database DATABASE
122
- Database name
123
- -q QUERY, --query QUERY
124
- SQL query
125
- -o {stdout,file}, --out {stdout,file}
126
- CSV destination
127
- -f DESTINATION_FILE, --destination_file DESTINATION_FILE
128
- CSV destination file
129
- -D DELIMITER, --delimiter DELIMITER
130
- CSV delimiter
131
- -Q QUOTECHAR, --quotechar QUOTECHAR
132
- CSV quote character
133
-
134
- .. |Pypi| image:: https://img.shields.io/pypi/v/sql2csv.svg
135
- :target: https://pypi.org/project/sql2csv
136
- .. |Build Status| image:: https://travis-ci.org/gabfl/sql2csv.svg?branch=master
137
- :target: https://travis-ci.org/gabfl/sql2csv
138
- .. |codecov| image:: https://codecov.io/gh/gabfl/sql2csv/branch/master/graph/badge.svg
139
- :target: https://codecov.io/gh/gabfl/sql2csv
140
- .. |MIT licensed| image:: https://img.shields.io/badge/license-MIT-green.svg
141
- :target: https://raw.githubusercontent.com/gabfl/sql2csv/master/LICENSE
142
-
143
- Platform: UNKNOWN
144
- Classifier: Topic :: Database
145
- Classifier: Topic :: Database :: Database Engines/Servers
146
- Classifier: License :: OSI Approved :: MIT License
147
- Classifier: Operating System :: MacOS
148
- Classifier: Operating System :: POSIX :: Linux
149
- Classifier: Natural Language :: English
150
- Classifier: Programming Language :: Python :: 3
151
- Classifier: Programming Language :: Python
152
- Classifier: Development Status :: 4 - Beta
sql2csv-1.2/setup.py DELETED
@@ -1,40 +0,0 @@
1
- from setuptools import setup
2
-
3
- try:
4
- import pypandoc
5
- long_description = pypandoc.convert('README.md', 'rst')
6
- except(IOError, ImportError):
7
- long_description = open('README.md').read()
8
-
9
- setup(
10
- name='sql2csv',
11
- version='1.2',
12
- description='Run MySQL and PostgreSQL queries and store result in CSV',
13
- long_description=long_description,
14
- author='Gabriel Bordeaux',
15
- author_email='pypi@gab.lc',
16
- url='https://github.com/gabfl/sql2csv',
17
- license='MIT',
18
- packages=['sql2csv'],
19
- package_dir={'sql2csv': 'src'},
20
- install_requires=['argparse', 'PyYAML', 'pymysql',
21
- 'psycopg2-binary'], # external dependencies
22
- entry_points={
23
- 'console_scripts': [
24
- 'sql2csv = sql2csv.sql2csv:main',
25
- ],
26
- },
27
- classifiers=[ # see https://pypi.python.org/pypi?%3Aaction=list_classifiers
28
- 'Topic :: Database',
29
- 'Topic :: Database :: Database Engines/Servers',
30
- 'License :: OSI Approved :: MIT License',
31
- 'Operating System :: MacOS',
32
- 'Operating System :: POSIX :: Linux',
33
- 'Natural Language :: English',
34
- # 'Programming Language :: Python :: 2.7',
35
- 'Programming Language :: Python :: 3',
36
- 'Programming Language :: Python',
37
- 'Development Status :: 4 - Beta',
38
- # 'Development Status :: 5 - Production/Stable',
39
- ],
40
- )
@@ -1,152 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: sql2csv
3
- Version: 1.2
4
- Summary: Run MySQL and PostgreSQL queries and store result in CSV
5
- Home-page: https://github.com/gabfl/sql2csv
6
- Author: Gabriel Bordeaux
7
- Author-email: pypi@gab.lc
8
- License: MIT
9
- Description: sql2csv
10
- =======
11
-
12
- |Pypi| |Build Status| |codecov| |MIT licensed|
13
-
14
- Run MySQL and PostgreSQL queries and store the results in CSV.
15
-
16
- Why sql2csv
17
- -----------
18
-
19
- ``sql2csv`` is a small utility to run MySQL and PostgreSQL queries and
20
- store the output in a CSV file.
21
-
22
- In some environments like when using MySQL or Aurora in AWS RDS,
23
- exporting queries’ results to CSV is not available with native tools.
24
- ``sql2csv`` is a simple module that offers this feature.
25
-
26
- Installation
27
- ------------
28
-
29
- .. code:: bash
30
-
31
- pip3 install sql2csv
32
-
33
- # Basic usage
34
- mysql [...] -e "SELECT * FROM table" | sql2csv
35
- # or
36
- psql [...] -c "SELECT * FROM table" | sql2csv
37
-
38
- Example
39
- -------
40
-
41
- From stdin
42
- ~~~~~~~~~~
43
-
44
- For simple queries you can pipe a result directly from ``mysql`` or
45
- ``psql`` to ``sql2csv``.
46
-
47
- For more complex queries, it is recommended to use the CLI (see below)
48
- to ensure a properly formatted CSV.
49
-
50
- .. code:: bash
51
-
52
- mysql -U root -p"secret" my_db -e "SELECT * FROM some_mysql_table;" | sql2csv
53
-
54
- id,some_int,some_str,some_date
55
- 1,12,hello world,2018-12-01 12:23:12
56
- 2,15,hello,2018-12-05 12:18:12
57
- 3,18,world,2018-12-08 12:17:12
58
-
59
- .. code:: bash
60
-
61
- psql -U postgres my_db -c "SELECT * FROM some_pg_table" | sql2csv
62
-
63
- id,some_int,some_str,some_date
64
- 1,12,hello world,2018-12-01 12:23:12
65
- 2,15,hello,2018-12-05 12:18:12
66
- 3,18,world,2018-12-08 12:17:12
67
-
68
- Using ``sql2csv`` CLI
69
- ~~~~~~~~~~~~~~~~~~~~~
70
-
71
- Output to stdout
72
- ^^^^^^^^^^^^^^^^
73
-
74
- .. code:: bash
75
-
76
- $ sql2csv --engine mysql \
77
- --database my_db --user root --password "secret" \
78
- --query "SELECT * FROM some_mysql_table"
79
-
80
- 1,12,hello world,2018-12-01 12:23:12
81
- 2,15,hello,2018-12-05 12:18:12
82
- 3,18,world,2018-12-08 12:17:12
83
-
84
- Output saved in a file
85
- ^^^^^^^^^^^^^^^^^^^^^^
86
-
87
- .. code:: bash
88
-
89
- $ sql2csv --engine mysql \
90
- --database my_db --user root --password "secret" \
91
- --query "SELECT * FROM some_mysql_table" \
92
- --out file --destination_file export.csv
93
-
94
- # * Exporting rows...
95
- # ...done
96
- # * The result has been exported to export.csv.
97
-
98
- $ cat export.csv
99
- 1,12,hello world,2018-12-01 12:23:12
100
- 2,15,hello,2018-12-05 12:18:12
101
- 3,18,world,2018-12-08 12:17:12
102
-
103
- Usage
104
- -----
105
-
106
- .. code:: bash
107
-
108
- usage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER
109
- [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]
110
- [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR]
111
-
112
- optional arguments:
113
- -h, --help show this help message and exit
114
- -e {mysql,postgresql}, --engine {mysql,postgresql}
115
- Database engine
116
- -H HOST, --host HOST Database host
117
- -P PORT, --port PORT Database port
118
- -u USER, --user USER Database user
119
- -p PASSWORD, --password PASSWORD
120
- Database password
121
- -d DATABASE, --database DATABASE
122
- Database name
123
- -q QUERY, --query QUERY
124
- SQL query
125
- -o {stdout,file}, --out {stdout,file}
126
- CSV destination
127
- -f DESTINATION_FILE, --destination_file DESTINATION_FILE
128
- CSV destination file
129
- -D DELIMITER, --delimiter DELIMITER
130
- CSV delimiter
131
- -Q QUOTECHAR, --quotechar QUOTECHAR
132
- CSV quote character
133
-
134
- .. |Pypi| image:: https://img.shields.io/pypi/v/sql2csv.svg
135
- :target: https://pypi.org/project/sql2csv
136
- .. |Build Status| image:: https://travis-ci.org/gabfl/sql2csv.svg?branch=master
137
- :target: https://travis-ci.org/gabfl/sql2csv
138
- .. |codecov| image:: https://codecov.io/gh/gabfl/sql2csv/branch/master/graph/badge.svg
139
- :target: https://codecov.io/gh/gabfl/sql2csv
140
- .. |MIT licensed| image:: https://img.shields.io/badge/license-MIT-green.svg
141
- :target: https://raw.githubusercontent.com/gabfl/sql2csv/master/LICENSE
142
-
143
- Platform: UNKNOWN
144
- Classifier: Topic :: Database
145
- Classifier: Topic :: Database :: Database Engines/Servers
146
- Classifier: License :: OSI Approved :: MIT License
147
- Classifier: Operating System :: MacOS
148
- Classifier: Operating System :: POSIX :: Linux
149
- Classifier: Natural Language :: English
150
- Classifier: Programming Language :: Python :: 3
151
- Classifier: Programming Language :: Python
152
- Classifier: Development Status :: 4 - Beta
@@ -1,4 +0,0 @@
1
- argparse
2
- PyYAML
3
- pymysql
4
- psycopg2-binary
File without changes
File without changes
File without changes