semvec/pypi-packages huggingface dataset:
fireclass 1.0.4
Firestore + Dataclass: declare and interact with your Firestore models using dataclasses.
Requires Python: >=3.7
Keywords: dataclasses firestore google-cloud google-cloud-platform orm

# Fireclass

[![Python Version](https://img.shields.io/pypi/pyversions/fireclass.svg)](https://pypi.org/project/fireclass/)
[![PyPi Version](https://img.shields.io/pypi/v/fireclass.svg)](https://pypi.org/project/fireclass/)
[![Build Status](https://travis-ci.org/nabla-c0d3/fireclass.svg?branch=master)](https://travis-ci.org/nabla-c0d3/fireclass)

Firestore + Dataclass: declare and interact with your Firestore models using Python dataclasses.

## Installation

`pip install fireclass`

## Sample usage

```python
from dataclasses import dataclass
from enum import Enum

from google.cloud import firestore
from fireclass import Document, initialize_with_firestore_client


class MembershipLevelEnum(Enum):
    NONE = 1
    INTERMEDIATE = 2
    FULL = 3


# Define a new type of document as a dataclass
@dataclass
class Person(Document):
    email_address: str
    age: int

    # Enum fields are supported
    membership: MembershipLevelEnum


# Initialize access to the Firestore DB
client = firestore.Client.from_service_account_json("travis-ci-test-suite-service-account.json")
initialize_with_firestore_client(client)

# Create a new person
person = Person(email_address="test@test.com", age=30, membership=MembershipLevelEnum.INTERMEDIATE)

# Save the person to the DB
person.create()

# Update some fields
person.age = 31
person.membership = MembershipLevelEnum.NONE
person.update()

# Fetch this specific person
fetched_person = Person.get_document(person.id)

# Query for persons
for found_person in Person.where("age", "==", 31).stream():
    print(found_person)

# Delete the document from the DB
person.delete()
```
timedict 0.0.3
A self updating dictionary like structure
Requires Python: >=3.5

# Time Dictionary
![Unittests](https://github.com/Matshec/time_dict/workflows/Unittests/badge.svg)

Now objects age too! - 
Automatically manage your objects based on age

### How to install
`> pip install timedict`

### Overview
This module implements self-updating structure that is able to handle updating and removing object based on age.
Objects added to this structure are assigned timestamp at insertion, then when age of object is exceeded optional
action function is called and object is removed from the structure.
### NOTE
When using this structure you must explicitly delete it due to thread locking either by
calling `destroy()` method or deleting it as `del d` or the interpreter will hang at exit

### Example Usage
```python
from time_dict import TimeDict
cache = TimeDict(action_time=2, poll_time=0.5)
key = '1'
cache[key] = 1
key in cache
del cache
```
---
### Main parameters are:

    action_time - which specifies age in second at which objects should be deleted - 
                time when actions should be performed and object will be deleted from structure

    poll_time - frequency in seconds of polling the objects for age timeout,
                experimentally should be around 1/4 of the action_time or less. 
                Please not that too frequent polling
                may negatively affect you application performance

    action  -   function that is called on object age timeout. 
                Signature is 'fn(key:Any, value:Any) -> None'

    no_delete - do not delete objects when actions was called


Class **PARTIALLY**  implements dictionary interface, implementations allows for:
```python
d = TimeDict(action_time=2, poll_time=0.5)
insertion:
    d[key] = value
updating:
    NOTE: updating only changes the value, age remains unchanged
    d[key] = value
deletion:
      del d[key]
testing for membership:
    key in d
checking length:
    len(d)
```
All of the above method have optimistic time complexity of O(1)

Rest of the dictionary interface is not implemented by design.

### Methods are:
`clear() → None`

Safely clear all data in the structure :raises Exception

`destroy() → None`

Destroys the structure, must be called to properly deinitialize it

`flush() → None`


Flush all the objects by calling the action function, 
does not remove objects Does not respect object age, 
calls action method on all objects :raises Exception if updated thread died