semvec/pypi-packages huggingface dataset:
tsih 0.1.9
A lightweight library to store an object's history into a SQL database
Keywords: history,sql,records

# TSIH - A dict with a HISTory

`tsih.Dict` is a type of `UserDict` that allows versioning, backed up by a `sqlite3` database.

* Transparent operation
* Only changes (deltas) are stored.
* Forward-filling of values. A value is reused in future versions, unless it changes.
* Auto-versioning option (off by default), to produce a new version every time a value change happens.
* Ability to store related entries as separate dictionaries. Each `tsih.Dict` has a `dict_name` that is used in the database to identify the dictionary.
* Tuple-based indexing. Get and set values by `dict_name`, `version` and `key`.

## Usage and examples

`tsih.Dict` objects can be used just like regular dictionaries:

```python
>>> from tsih import Dict
>>> a = Dict()
>>> a['test'] = True
>>> a
{'test': True}
>>> a.get('missing', 5)
5
>>> a['missing']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'missing'
```

But at any point, new versions can be produced:

```python
>>> a.version
0
>>> a['start'] = 'now'
>>> a
{'test': True, 'start': 'now'}
>>> a.version = 1
>>> a['start'] = 'one version ago'
>>> a
{'test': True, 'start': 'one version ago'}
```

Previous values can be accessed using tuple keys, i.e., (version, key):

```python
>>> a[(0, 'start')]
'now'
>>> a[(1, 'start')]
'one version ago'
```

Each version only "records" changes, but later versions (even if they don't exist yet) inherit unchanged values from the previous ones:

```python
>>> a[(5, 'start')]  
'one version ago'
>>> a.version = 5
>>> # Until the value is changed
>>> a['start'] = '4 versions ago' 
>>> a[(5, 'start')]
'4 versions ago'
```

You can access *every* state of the Dict using `None` in place of the version and/or the key.
In that case, we will get an iterator, which we can turn into a list explicitly or with the `.value` method.

For example, here we get all the changes to the `start` key:

```python
>>> a[(None, 'start')].value() # 
[(0.0, 'now'), (1.0, 'one version ago'), (5.0, '4 versions ago')]
```

Similarly, to get the keys and values at a specific version:

```python
>>> list(a[(0, None)])
[('start', 'now'), ('test', True)]
```

Or, we can combine both to get the keys and values at every version:

```python
>>> a[(None, None)].value()
[(0.0, 'start', 'now'), (1.0, 'start', 'one version ago'), (5.0, 'start', '4 versions ago'), (0.0, 'test', True), (1.0, 'test', True), (5.0, 'test', True)]
```

## Use cases

Tsih was originally part of the [Soil](https://github.com/gsi-upm/soil) Agent-Based Social Simulation framework, where both the environment and the agents need to keep track of state (i.e., attribute) changes.
django-ram 0.1.2
Django Role based Access Management.
Requires Python: >=3.6

# Django RAM

Role based user access management for Django.

# Requirements

* Python 3.6+
* Django 4.1, 4.0, 3.2, 3.1, 3.0

# Installation

    pip install django-ram
    
Optionally install with rest framework support:

    pip install django-ram[rest_framework]

    
Add `django_ram'` to your `INSTALLED_APPS` setting.
```python
INSTALLED_APPS = [
    ...
    'django_ram',
]
```

    ./manage.py migrate

# Overview

## User Model

Add the `RolesMixin` to your user model.

```python
from django_ram.models import RolesMixin


class CustomUser(AbstractUser, RolesMixin):
    pass
```

Also remember to configure `AUTH_USER_MODEL` in your `settings.py` module.


## Declarative Roles
some_app/roles.py

```python
from django_ram.definition import RoleDefinition


class AdminRole(RoleDefinition):
    name = "Admin"
    description = "System administrator."


class AuthorRole(RoleDefinition):
    name = "Author"
    description = "A writer of a book, article, or document."
```

Roles will be created (or updated) post migration to reflect role definitions in `roles.py` files.

Role names have to be globally unique.


## Django Admin

Register the admin class (or subclass it to expand functionality.)

```python
from django.contrib import admin
from django_ram.admin import UserAdmin

...

admin.site.register(YourUserModel, UserAdmin)
```


## Rest Framework Support

```python
from django_ram.rest_framework import HasRoleBasePermission, has_role
from some_app.roles import AuthorRole


class HasAuthorRole(HasRoleBasePermission):
    role_definition = AuthorRole


class PublicationViewSet(viewsets.ModelViewset):
    permission_classes = [
        has_role(AuthorRole),
        #  Is equivelant to:
        HasAuthorRole,
    ]
```
fast1dkmeans 0.1.2
A python package for optimal 1d k-means clustering.
Requires Python: >=3.8

[![build](https://github.com/Feelx234/fast1dkmeans/actions/workflows/pythonapp.yml/badge.svg)](https://github.com/Feelx234/fast1dkmeans/actions)

fast1dkmeans
========

A Python library which implements several variations of optimal *k*-means clustering on 1D data, based on the algorithms presented by Gronlund et al. (2017). This package is inspired by the [kmeans1d](https://github.com/dstein64/kmeans1d) package but extends it by implementing additional algorithms, in particular those with reduced memory requirements O(n) instead of O(kn).

There are several different ways to compute the optimal k-means clustering in 1d.
Currently the package implements the following methods:
- `"binary-search-interpolation"` *default* [O(n lg(U) ), O(n) space, "wilber-interpolation"]
- `"dynamic-programming-kn"` [O(kn), O(kn) space]
- `"dynamic-programming-space"` [O(kn), O(n) space, "dp-linear"]
- `"binary-search-normal"` [O(n lg(U) ), O(n) space, section 2.4, "wilber-binary"]



The code is written in Python and relies on the [numba](https://numba.pydata.org/) compiler for speed.

Requirements
------------

*fast1dkmeans* relies on `numpy` and `numba` which currently support python 3.8-3.10.

Installation
------------

[fast1dkmeans](https://pypi.python.org/pypi/fast1dkmeans) is available on PyPI, the Python Package Index.

```sh
$ pip3 install fast1dkmeans
```

Example Usage
-------------

```python
import fast1dkmeans

x = [4.0, 4.1, 4.2, -50, 200.2, 200.4, 200.9, 80, 100, 102]
k = 4

clusters = fast1dkmeans.cluster(x, k)

print(clusters)   # [1, 1, 1, 0, 3, 3, 3, 2, 2, 2]
```

Important notice: On first usage the the code is compiled once which may take about 30s. On subsequent usages this is no longer necessary and execution is much faster.

Tests
-----

Tests are in [tests/](https://github.com/Feelx234/fast1dkmeans/blob/master/tests).

```sh
# Run tests
$ python3 -m pytest .
```

License
-------

The code in this repository has an BSD 2-Clause "Simplified" License.

See [LICENSE](https://github.com/Feelx234/fast1dkmeans/blob/master/LICENSE).

References
----------

[1] Gronlund, Allan, Kasper Green Larsen, Alexander Mathiasen, Jesper Sindahl Nielsen, Stefan Schneider,
and Mingzhou Song. "Fast Exact K-Means, k-Medians and Bregman Divergence Clustering in 1D."
ArXiv:1701.07204 [Cs], January 25, 2017. http://arxiv.org/abs/1701.07204.