semvec/pypi-packages huggingface dataset:
k3portlock 0.1.7
Cross-process lock using TCP port binding
License: MIT
Requires Python: >=3.9
Keywords: lock, process-lock, tcp, port, mutex

# k3portlock

[![Action-CI](https://github.com/pykit3/k3portlock/actions/workflows/python-package.yml/badge.svg)](https://github.com/pykit3/k3portlock/actions/workflows/python-package.yml)
[![Documentation Status](https://readthedocs.org/projects/k3portlock/badge/?version=stable)](https://k3portlock.readthedocs.io/en/stable/?badge=stable)
[![Package](https://img.shields.io/pypi/pyversions/k3portlock)](https://pypi.org/project/k3portlock)

k3protlock is a cross-process lock that is implemented with `tcp` port binding.

k3portlock is a component of [pykit3] project: a python3 toolkit set.


k3portlock is a cross-process lock that is implemented with `tcp` port binding.
Since no two processes could bind on a same TCP port.

k3portlock tries to bind **3** ports on loopback ip `127.0.0.1`.
If a Portlock instance succeeds on binding **2** ports out of 3,
it is considered this instance has acquired the lock.




# Install

```
pip install k3portlock
```

# Synopsis

```python

#!/usr/bin/env python

import time
import k3portlock

if __name__ == "__main__":

    # Basic lock acquisition and release
    lock = k3portlock.Portlock("mylock")

    # Try to acquire lock (non-blocking)
    if lock.try_lock():
        print("Lock acquired")
        # Do some work
        lock.release()
        print("Lock released")
    else:
        print("Failed to acquire lock")

    # Blocking lock acquisition with timeout
    lock2 = k3portlock.Portlock("mylock2", timeout=5)
    try:
        lock2.acquire()  # Will wait up to 5 seconds
        print("Lock acquired")
        time.sleep(1)
        lock2.release()
        print("Lock released")
    except k3portlock.PortlockTimeout:
        print("Timeout while waiting for lock")

    # Context manager usage (recommended)
    with k3portlock.Portlock("mylock3", timeout=3) as lock:
        print("Lock acquired via context manager")
        # Do some work
        time.sleep(0.5)
    print("Lock automatically released")

    # Check if lock is held (without acquiring)
    lock4 = k3portlock.Portlock("testlock")
    print(lock4.has_locked())  # False

    lock4.acquire()
    another_lock = k3portlock.Portlock("testlock")
    print(another_lock.has_locked())  # False (different instance)
    lock4.release()

```

#   Author

Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>

#   Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>


[pykit3]: https://github.com/pykit3
k3net 0.1.5
Network utilities for IP address detection and classification
License: MIT
Requires Python: >=3.9
Keywords: network, ip, ipv4, host, address

# k3net

[![Action-CI](https://github.com/pykit3/k3net/actions/workflows/python-package.yml/badge.svg)](https://github.com/pykit3/k3net/actions/workflows/python-package.yml)
[![Documentation Status](https://readthedocs.org/projects/k3net/badge/?version=stable)](https://k3net.readthedocs.io/en/stable/?badge=stable)
[![Package](https://img.shields.io/pypi/pyversions/k3net)](https://pypi.org/project/k3net)

Utility functions for network related operation.

k3net is a component of [pykit3] project: a python3 toolkit set.




# Install

```
pip install k3net
```

# Synopsis

```python

#!/usr/bin/env python

import k3net

if __name__ == "__main__":

    # Check if an IP is valid IPv4
    print(k3net.is_ip4("192.168.0.1"))  # True
    print(k3net.is_ip4("invalid"))      # False

    # Check if IP is public or private (INN)
    print(k3net.is_pub("1.2.3.4"))      # True
    print(k3net.is_inn("192.168.0.1"))  # True

    # Get IP class
    print(k3net.ip_class("1.2.3.4"))      # PUB
    print(k3net.ip_class("192.168.0.1"))  # INN

    # Select IPs by class
    ips = ["1.2.3.4", "192.168.0.1", "10.0.0.1"]
    print(k3net.choose_pub(ips))  # ['1.2.3.4']
    print(k3net.choose_inn(ips))  # ['192.168.0.1', '10.0.0.1']

    # Prefer public or private IPs
    print(k3net.ips_prefer(ips, k3net.PUB))  # Public IPs first
    print(k3net.ips_prefer(ips, k3net.INN))  # Private IPs first

    # Get host IP addresses
    host_ips = k3net.get_host_ip4()
    print(host_ips)  # List of host IPv4 addresses

    # IP to number conversion
    num = k3net.ip_to_num("192.168.0.1")
    print(num)  # 3232235521
    print(k3net.num_to_ip(num))  # '192.168.0.1'

```

#   Author

Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>

#   Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>


[pykit3]: https://github.com/pykit3
entropy-invariant 1.1.0
Invariant entropy estimation using nearest neighbor methods
License: MIT
Requires Python: >=3.8
Keywords: entropy, mutual information, information theory, k-nn, nearest neighbor

# entropy-invariant

A Python package implementing an improved nearest neighbor method for estimating differential entropy for continuous variables. This is a port of the Julia [EntropyInvariant](https://github.com/truongfelix/EntropyInvariant-private) package.

## Key Features

- **Invariant under change of variables**: Scale and translation invariant entropy estimation
- **Always positive**: Solves Edwin Thompson Jaynes' limiting density of discrete points problem
- **Multiple methods**: Supports invariant (default), k-NN, and histogram methods

## Installation

```bash
pip install entropy-invariant
```

Or install from source:

```bash
pip install -e .
```

## Usage

```python
import numpy as np
from entropy_invariant import entropy, mutual_information

# Generate random data
n = 1000
x = np.random.rand(n)
y = 2 * x + np.random.rand(n)

# Compute entropy (invariant method, default)
h = entropy(x)
print(f"Entropy: {h}")

# Entropy is invariant under scaling and translation
h_scaled = entropy(1e5 * x - 123.456)
print(f"Entropy (scaled): {h_scaled}")  # Same value!

# Mutual information
mi = mutual_information(x, y)
print(f"Mutual Information: {mi}")

# Different methods
h_knn = entropy(x, method="knn")
h_hist = entropy(x, method="histogram", nbins=20)
```

## Available Functions

### Core Entropy
- `entropy(X, method="inv", k=3, base=e, ...)` - Unified entropy interface
- `entropy_inv(X, ...)` - Invariant method (default)
- `entropy_knn(X, ...)` - k-NN method
- `entropy_hist(X, ...)` - Histogram method

### Information Theory
- `conditional_entropy(X, Y, ...)` - H(Y|X)
- `mutual_information(X, Y, ...)` - I(X;Y)
- `conditional_mutual_information(X, Y, Z, ...)` - I(X;Y|Z)
- `normalized_mutual_information(X, Y, ...)` - NMI
- `interaction_information(X, Y, Z, ...)` - Three-way interaction

### Partial Information Decomposition
- `redundancy(X, Y, Z, ...)` - Shared information
- `unique(X, Y, Z, ...)` - Unique information
- `synergy(X, Y, Z, ...)` - Synergistic information

### Optimized Matrix Functions
- `MI(X, ...)` - Pairwise mutual information matrix
- `CMI(X, Z, ...)` - Pairwise conditional MI matrix

## Authors

- Felix Truong
- Alexandre Giuliani

## License

MIT