semvec/pypi-packages huggingface dataset:
functiongroup 0.1.5
Python utility to implement protocols with pure functions
License: MIT
Requires Python: >=3.11,<4.0
Keywords: functional,protocol,python

# functiongroup
FunctionGroup is a Python utility designed to simplify the implementation of protocols using pure functions. If you've ever found yourself creating classes solely to group related functions when implementing protocols, this package offers an elegant solution.

## Example

Let's consider a scenario where you have a protocol for saving and loading dictionaries, like the `DictIO` example below:

```python
from typing import Protocol


class DictIO(Protocol):
    def save_dict(self, dict_: dict[str, str], file_name: str) -> None:
        ...

    def load_dict(self, file_name: str) -> dict[str, str]:
        ...
```

Traditionally, you'd implement this protocol by creating a class:

```python
import json


class JsonDictIO(DictIO):
    def save_dict(self, dict_: dict[str, str], file_name: str) -> None:
        with open(file_name, "w") as f:
            json.dump(dict_, f)

    def load_dict(self, file_name: str) -> dict[str, str]:
        with open(file_name) as f:
            return json.load(f)

dict_io = JsonDictIO()
```

However, you may wonder why you need a class when you're not modifying its state or using any dunder methods. You're essentially using the class to group related functions, so why not use a `FunctionGroup` instead?

```python
from functiongroup import FunctionGroup


json_dict_io = FunctionGroup()

@json_dict_io.register
def save_dict(dict_: dict[str, str], file_name: str) -> None:
    with open(file_name, "w") as f:
        json.dump(dict_, f)


@json_dict_io.register
def load_dict(file_name: str) -> dict[str, str]:
    with open(file_name) as f:
        return json.load(f)

dict_io = json_dict_io()
```

This approach encourages a more functional code style and provides all the advantages of pure functions.
cythoncartesian 0.10
Cartesian Product - 6x faster than itertools.product - 10x less memory
License: MIT
Keywords: cython,cartesian,product,itertools


# Cartesian Product - 6x faster than itertools.product - 10x less memory

## pip install cythoncartesian

### Tested against Windows / Python 3.11 / Anaconda


## Cython (and a C/C++ compiler) must be installed



```python
Generate the Cartesian product of input iterables.

Parameters:
-----------
*args : list of iterable
	Input iterables for which the Cartesian product will be computed.
outputdtype (optional) :
	dtype of output array
Returns:
--------
numpy.ndarray
	2D array containing the Cartesian product of the input iterables.

Notes:
------
This function efficiently computes the Cartesian product of the input iterables
using Cython implementation. It outperforms the equivalent functionality provided
by itertools.product, and returns a NumPy array (not a list of tuples like itertools.product).

Examples:
---------
	from cythoncartesian import cartesian_product

	# Mem usage 2 GB
	# Out[4]:
	# array([[0, 0, 0, ..., 0, 0, 0],
	#        [1, 0, 0, ..., 0, 0, 0],
	#        [2, 0, 0, ..., 0, 0, 0],
	#        ...,
	#        [5, 7, 7, ..., 7, 7, 7],
	#        [6, 7, 7, ..., 7, 7, 7],
	#        [7, 7, 7, ..., 7, 7, 7]], dtype=uint8)
	# %timeit dataresults=cartesian_product(*args2)
	# 2.65 s ± 163 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
	# dataresults.shape
	# Out[6]: (134217728, 9)
	

	# itertools.product
	# Mem usage 16 GB

	# import itertools
	# %timeit (list(itertools.product(*args2)))
	# 11.5 s ± 203 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


	# --------------------------------------------------------------------------
	# Mem usage 1.2 GB
	# args = [[411, 231.33, 4342, 12341, 1.142, 1.33, 13],
	#         [34, 231.33, 4132, 1231],
	#          [14, 44, 23454.1, .1, 23, 1],
	#          [9, 12, 1, 3, 32, 23, 21, 31],
	#          [1114, 44, 23454.1, .1, 23, 1],
	#         ]+[list(range(6)),list(range(3)),list(range(3)),list(range(3))
	#     ,list(range(3))]+[list(range(6))]
	# %timeit dataresults=cartesian_product(*args)
	# 621 ms ± 46.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


	# Mem usage 4 GB
	# import itertools
	# %timeit (list(itertools.product(*args)))
	# 2.13 s ± 26.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

```
drf-custom-permissions 0.1.2
Django Rest Framework custom permissions classes
License: MIT
Requires Python: >=3.9,<4.0
Keywords: drf,django,Django,django rest framework,drf-permission,permissions,python

# drf-permissions

## Installation

```pip
pip install drf-custom-permissions
```

## Usage

### APIView IsNotAuthenticated permission

```python
# views.py

from rest_framework.views import APIView
from drf_custom_permissions import IsNotAuthenticated

class ExampleIsNotAuthenticatedAPIVIew(APIView):
    permission_classes = (IsNotAuthenticated,)
    ...
```

### APIView with HasGroupPermission

```python
# views.py

from rest_framework.views import APIView
from drf_custom_permissions import HasGroupPermission

class ExampleIsNotAuthenticatedAPIVIew(APIView):
    permission_classes = (HasGroupPermission,)
    permission_groups = ('Designers', 'Developers',)
    ...
```