# sc4py

Utilities for date/time, environment parsing, dynamic class loading, percentages, string-to-bool conversion, choice tuples, and in-memory ZIP reading.

## Quick examples

```python
from sc4py.datetime import now_str
from sc4py.env import env_as_bool
from sc4py.number import percentage

print(now_str())
print(env_as_bool("FEATURE_ENABLED", default="true"))
print(percentage(45, 60))  # 75.0
```

## Date and time (`sc4py.datetime`)

* `today` - Alias for `date.today`
* `now` - Alias for `datetime.now`
* `now_str()` - Current datetime formatted as `%d-%m-%Y %H:%M:%S`
* `this_month()` - Current month as integer (`1..12`)
* `others_months()` - List of all months except current
* `daterange(start, end, step=timedelta(1))` - Generator from `start` to `end` (inclusive)

## Environment helpers (`sc4py.env`)

* `env(name, default=None, wrapped=False)` - Reads env var value; with `wrapped=True`, strips leading/trailing single quotes
* `env_as_list(name, default='', delimiter=',', wrapped=False)` - Parses env var as list
* `env_as_list_of_maps(name, key, default='', delimiter=',', wrapped=False)` - Parses env var as list of dicts with fixed key
* `env_as_bool(name, default=None, wrapped=False)` - Parses env var to bool/None via `str2bool`
* `env_as_int(name, default=None, wrapped=False)` - Parses env var to int/None
* `env_from_json(name, default='', wrapped=False)` - Parses env var as JSON

## Class helper (`sc4py.klass`)

* `instantiate_class(full_class_name, *args, **kwargs)` - Dynamic import and instantiation from dotted path

## Number helper (`sc4py.number`)

* `percentage(num1, num2, precision=2)` - Returns `num1 / num2 * 100` rounded by precision; returns `0.0` if any value is zero

## String helper (`sc4py.str`)

* `str2bool(v)` - Converts bool-like values to `True`/`False`/`None`
* Accepted true strings: `true`, `verdade`, `yes`, `sim`, `t`, `v`, `y`, `s`, `1`
* Accepted false strings: `false`, `falso`, `no`, `nao`, `não`, `f`, `n`, `0`

## Choice helper (`sc4py.choice`)

* `to_choice(*args)` - Converts enums/values to list of `(value, label)` tuples
* If enum item has `description`, uses it as label; otherwise uses `value`

## ZIP helpers (`sc4py.zip`)

* `unzip_content(content, file_id=0, encoding='utf-8')` - Reads one file from ZIP bytes in memory by index (`int`) or filename (`str`), returning decoded `str` (or raw `bytes` when `encoding=None`)
* `unzip_csv_content(content, file_id=0, encoding='utf-8', **kwargs)` - Reads CSV from ZIP and returns `list[dict]`
* Raises `FileNotFoundInZipError` when file index/name is not found

```python
from sc4py.zip import unzip_csv_content

rows = unzip_csv_content(zip_bytes, file_id=0)
print(rows[0])
```


## 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.

