Metadata-Version: 2.1
Name: zut
Version: 0.9.2
Summary: Reusable Python utilities.
Author-email: Sébastien Hocquet <dev@ipamo.net>
Project-URL: Homepage, https://github.com/ipamo/zut
Project-URL: Bug Tracker, https://github.com/ipamo/zut/issues
Keywords: reusable,util,utils,common,commons,base,flexout,csv,excel,tabulate,smb,samba,share,out_table,out_file,db,DbAdapter
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.7.3
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: typing-extensions ; python_version < "3.8"
Provides-Extra: commons
Requires-Dist: colorlog ; extra == 'commons'
Requires-Dist: tabulate ; extra == 'commons'
Requires-Dist: pytz ; (python_version < "3.9") and extra == 'commons'
Requires-Dist: tzlocal ; (python_version < "3.9" or sys_platform == "win32") and extra == 'commons'
Requires-Dist: tzdata ; (python_version >= "3.9" and sys_platform == "win32") and extra == 'commons'
Provides-Extra: excel
Requires-Dist: openpyxl ; extra == 'excel'
Requires-Dist: defusedxml ; extra == 'excel'
Provides-Extra: mssql
Requires-Dist: pyodbc ; extra == 'mssql'
Requires-Dist: sqlparse ; extra == 'mssql'
Requires-Dist: sqlparams ; extra == 'mssql'
Provides-Extra: mysql
Requires-Dist: mysqlclient ; extra == 'mysql'
Requires-Dist: sqlparse ; extra == 'mysql'
Provides-Extra: pg
Requires-Dist: psycopg ; extra == 'pg'
Requires-Dist: sqlparse ; extra == 'pg'
Provides-Extra: smb
Requires-Dist: smbprotocol ; extra == 'smb'
Provides-Extra: systemd
Requires-Dist: systemd-python ; (sys_platform == "linux") and extra == 'systemd'

Zut
===

Reusable Python utilities.


## Installation

Zut package is published [on PyPI](https://pypi.org/project/zut/):

```sh
pip install zut
```


## Usage examples

See also [full documentation](https://ipamo.net/zut) (including [API reference](https://ipamo.net/zut/latest/api-reference.html)).


### Configure logging

```py
from zut import configure_logging
configure_logging()
```

### Flexible output

Write text or tabular data to a flexible, easily configurable output: CSV or Excel file, or tabulated stdout/stderr.

The output file may be on the local file system or on a Windows/Samba share (including when the library is used on Linux).

Export text to stdout or to a file:

```py
import sys
from zut import out_file

with out_file(filename or sys.stdout) as f:
    f.write("Content")
```
    
Export tabular data to stdout or to a file:

```py
import sys
from zut import out_table

with out_table(filename or sys.stdout, headers=["Id", "Word"]) as t:
    t.append([1, "Hello"])
    t.append([2, "World"])
```

Tabular data can also be exported using dictionnaries (in this case, headers will be detected automatically by the library):

```py
import sys
from zut import out_table

with out_table(filename or sys.stdout) as t:
    t.append({'id': 1, 'name': "Hello"})
    t.append({'id': 2, 'col3': True})
```

If `filename` has extension with `.xlsx`, output will be in Excel 2010 format.
Otherwise it will be in CSV format.

If `filename` starts with `\\`, output will be done on the corresponding Windows/Samba share.
To indicate Samba credentials, call `configure_smb_credentials` before using function `out_table`.
Example:

```py
from zut import out_table, configure_smb_credentials

configure_smb_credentials(user=..., password=...)

with out_table(r"\\server\share\path\to\file") as o:
    ...
```


## Legal

This project is licensed under the terms of the [MIT license](https://raw.githubusercontent.com/ipamo/zut/main/LICENSE.txt).
