# sc4net

Network helpers for HTTP(S) and FTP downloads, with convenience JSON and ZIP readers.

## Quick examples

```python
from sc4net import get_json, get_zip_csv_content

health = get_json("https://example.com/health")
rows = get_zip_csv_content("https://example.com/files/report.zip", file_id=0)

print(health)
print(rows[:2])
```

## Core behavior

* For URLs starting with `ftp://`, it uses Python stdlib `ftplib`
* For other URLs, it uses Python stdlib `urllib.request`
* On non-OK responses, raises `http.client.HTTPException` enriched with `status`, `reason`, `headers`, and `url`

## Read operations

* `requests_get(url, headers=None, encoding='utf-8', decode=True, **kwargs)` - Returns `str` by default, or `bytes` when `decode=False`/`encoding=None`
* `get(...)` - Alias for `requests_get(...)`
* `get_json(url, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)` - Reads content and parses JSON
* `get_zip(url, headers=None, **kwargs)` - Returns `zipfile.ZipFile` loaded in memory
* `get_zip_content(url, headers=None, file_id=0, encoding='utf-8', **kwargs)` - Reads a file from remote ZIP by index or filename
* `get_zip_csv_content(url, headers=None, file_id=0, encoding='utf-8', unzip_kwargs=None, **kwargs)` - Reads CSV from remote ZIP and returns `list[dict]`

## Write operations

* `post(url, data=None, json_data=None, headers=None, encoding='utf-8', decode=True, **kwargs)` - Sends POST request and returns decoded content by default
* `post_json(url, data=None, json_data=None, headers=None, encoding='utf-8', json_kwargs=None, **kwargs)` - Sends POST request and parses JSON response

## Not implemented yet

* `put(...)`
* `put_json(...)`
* `delete(...)`
* `delete_json(...)`

All methods above currently raise `NotImplementedError`.


## LICENSE

The MIT License (MIT)

Copyright (c) 2019 kelsoncm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

