Metadata-Version: 2.3
Name: djmapl
Version: 0.6.0
Summary: Django Utilities used at Screener and other projects
Author: Mittal Analytics Pvt Ltd
Author-email: Mittal Analytics Pvt Ltd <pratyush@hey.com>
Requires-Dist: django>=4.2.27
Requires-Dist: tqdm>=4.66
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/Mittal-Analytics/djmapl
Description-Content-Type: text/markdown

# DjMAPL

These are small Django utilities we find helpful and are used across projects.

## Utilities

### `call_concurrently`

Runs an async function over many items, at most `concurrency` at a time, with an optional `tqdm` progress bar. Results are yielded in completion order. A failed item yields its exception, with a `Failed item: <item>` note, instead of raising. Check each result:

```python
from djmapl.concurrency import call_concurrently

async for result in call_concurrently(
    concurrency=10,
    func=process_report,  # called as process_report(item, client=client)
    items=reports,
    show_progress=True,
    client=client,  # extra kwargs are passed to func
):
    if isinstance(result, Exception):
        # exc_info prints the traceback, including the `Failed item` note
        logger.error("Got error", exc_info=result)
```

`progress_callback(pbar, result)` runs after each item, even when the bar is hidden, e.g. to show a running total with `pbar.set_postfix_str(...)`.

All items are scheduled up front, so split very large inputs into batches. If you `break` out of the loop early, the remaining items are cancelled when the generator is closed. Use `contextlib.aclosing` to close it right away:

```python
from contextlib import aclosing

results = call_concurrently(...)
async with aclosing(results):
    async for result in results:
        if should_stop(result):
            break
```

## Running Tests

```
uv run pytest
```

## Publishing

```
uv version --bump minor
uv build

# save the credentials using `uv auth login upload.pypi.org`
uv publish --username __token__
```
