semvec/pypi-packages huggingface dataset:
whocreatedme 1.0.0
Automate file origin tracking in your projects
Requires Python: >=3.6

# Who Created Me
![banner](./assets/banner.webp)

## What is this?

This is a tool to automatically track which piece of code created your data.

In particular, every time you save a numpy array or a torch tensor, this tool
will automatically create a file with metadata about the code that created the data.

```bash
.
├── data.npy
└── .data.npy.who
```

```bash
cat .data.npy.who
───────┬─────────────────────────────────────────────────────────────────────
       │ File: .data.npy.who
───────┼─────────────────────────────────────────────────────────────────────
   1   │ Script Path: /path/to/example_numpy.py
   2   │ -------------------------------------------------------
   3   │ Code:
   4   │ -------------------------------------------------------
   5   │ import numpy as np
   6   │ import whocreatedme as wcme
   7   │ wcme.trace(numpy=True)
   8   │
   9   │ np.save("./test.npy", np.random.randn(50, 50))
  10   │ -------------------------------------------------------
───────┴─────────────────────────────────────────────────────────────────────

```



## How to use

You can either use the CLI or the Python API:

### CLI

```bash
python -m whocreatedme.cli <your-script> [--npsave] [--torchsave]
```

For example, to trace both `numpy` and `torch` `save` methods
for a script `script.py`, simply run:

```bash
python -m whocreatedme.cli script.py --npsave --torchsave
```

### Python API
Alternatively, you can trace the `numpy` and `torch` `save` methods
from your code by using the Python API:

```python
import numpy as np
import whocreatedme
whocreatedme.trace()

# this will automatically create a file `.data.npy.who` in the same directory as `data.npy`
np.save("data.npy", np.array([1, 2, 3]))
```

## Install

```bash
pip install whocreatedme
```

## Limitations

For now, this lightweight module only supports monkey-patching the `.save()`
methods in `numpy` and `torch`.

---
Images in README created with DALL-E.
dramatiq-header 0.1.2
Expose dramatiq headers via an options message through a thread-local variable in middleware.
Requires Python: >=3.10,<4.0
Keywords: dramatiq,header,dramatiq header,rabbitmq

<h1 align="center">
  🦅 Dramatiq Header Middleware for RabbitMQ
</h1>


# 🛠 Installation

```sh
pip install dramatiq-header
```

# ⬆️  Upgrade version

```sh
pip install dramatiq-header --upgrade
```

# ✏️  Usage


## Worker code:

```py
import dramatiq
from dramatiq.brokers.rabbitmq import RabbitmqBroker
from dramatiq_header import HeadersMessage # Import Middleware


rabbitmq_broker = RabbitmqBroker()
dramatiq.set_broker(rabbitmq_broker)


rabbitmq_broker.add_middleware(HeadersMessage()) # Add Middleware


@dramatiq.actor(queue_name='example')
def my_task(message):
    print(f'Message Received: {message}')
    print(HeadersMessage.get_headers()) # Get headers

```

> [!TIP]
> You can add middleware specifically to monitor a header key. For example:
```py
rabbitmq_broker.add_middleware(HeadersMessage('x-test-header'))
```


## Sender example

```py
import dramatiq
from dramatiq import Message
from dramatiq.brokers.rabbitmq import RabbitmqBroker


rabbitmq_broker = RabbitmqBroker()
dramatiq.set_broker(rabbitmq_broker)


def send_message(msg: str):
    message = Message(
        queue_name='example',
        actor_name='my_task',
        args=(msg, ),
        kwargs={},
        options={'x-test-header': 'test-header'}, # Send your entire header here
    )
    rabbitmq_broker.enqueue(message)


if __name__ == '__main__':
    send_message('test message')
```

## Output
![image](https://github.com/guedesfelipe/dramatiq-header/assets/25853920/bc5bd345-b694-4553-8daa-65172ac6b384)


> [!IMPORTANT]  
> This library does NOT transmit the header using the RabbitMQ header property; rather, it sends the header as metadata within the message that Dramatiq already dispatches.


---

<p align="center">
  <a href="https://ko-fi.com/guedesfelipe" target="_blank">
    <img src="https://user-images.githubusercontent.com/25853920/175832199-6c75d866-31b8-4209-bd1a-db116a6dd032.png" width=300 />
  </a>
</p>