Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tombulled/roster

Python object registers. Keep track of your classes, functions and data.
https://github.com/tombulled/roster

python register roster

Last synced: 23 days ago
JSON representation

Python object registers. Keep track of your classes, functions and data.

Awesome Lists containing this project

README

        

# roster
Python object registers. Keep track of your classes, functions and data.

## Installation
`roster` can be installed from [PyPI](https://pypi.org/project/roster/)
```console
pip install roster
```

## Usage:

### `Record`

#### Default Record
```python
from roster import Record

numbers: Record[int] = Record()

numbers(1)
numbers(2)
numbers(3)
```

```python
>>> numbers
[1, 2, 3]
```

#### Generate each `item`
```python
from roster import Record

characters: Record[str] = Record()

@characters.item
def character(char: str, /) -> str:
return char.upper()

character('a')
character('b')
character('c')
```

```python
>>> characters
['A', 'B', 'C']
```

### `Register`

#### Default Register
```python
from roster import Register

services: Register[str, type] = Register()

@services('youtube')
class YouTube: pass

@services('spotify')
class Spotify: pass
```

```python
>>> services
{'youtube': , 'spotify': }
```

#### Generate each `key`
```python
from roster import Register
from typing import Callable

functions: Register[str, Callable] = Register()

@functions.key
def function(name: str, /) -> str:
return name.upper()

@function('foo')
def foo(): pass

@function('bar')
def bar(): pass
```

```python
>>> functions
{'FOO': , 'BAR': }
```

#### Generate each `value`
```python
from roster import Register
from typing import Callable

functions: Register[str, Callable] = Register()

@functions.value
def function(name: str, /) -> str:
return name.upper()

@function('foo')
def foo(): pass

@function('bar')
def bar(): pass
```

```python
>>> functions
{: 'FOO', : 'BAR'}
```

#### Generate each `entry`
```python
from roster import Register
from typing import Tuple

identifiers: Register[str, str] = Register()

@identifiers.entry
def identifier(code: str, /) -> Tuple[str, str]:
return (code[0], code.upper())

identifier('foo')
identifier('bar')
```

```python
>>> identifiers
{'f': 'FOO', 'b': 'BAR'}
```