-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy path_base.py
More file actions
59 lines (46 loc) · 1.73 KB
/
Copy path_base.py
File metadata and controls
59 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from crawlee._utils.docs import docs_group
if TYPE_CHECKING:
from crawlee.storage_clients._base import StorageClient
from crawlee.storage_clients.models import DatasetMetadata, KeyValueStoreMetadata, RequestQueueMetadata
@docs_group('Storages')
class Storage(ABC):
"""Base class for storages."""
@property
@abstractmethod
def id(self) -> str:
"""Get the storage ID."""
@property
@abstractmethod
def name(self) -> str | None:
"""Get the storage name."""
@abstractmethod
async def get_metadata(self) -> DatasetMetadata | KeyValueStoreMetadata | RequestQueueMetadata:
"""Get the storage metadata."""
@classmethod
@abstractmethod
async def open(
cls,
*,
id: str | None = None,
name: str | None = None,
storage_client: StorageClient | None = None,
) -> Storage:
"""Open a storage, either restore existing or create a new one.
Args:
id: The storage ID.
name: The storage name.
storage_client: Underlying storage client to use. If not provided, the default global storage client
from the service locator will be used.
"""
@abstractmethod
async def drop(self) -> None:
"""Drop the storage, removing it from the underlying storage client and clearing the cache."""
@abstractmethod
async def purge(self) -> None:
"""Purge the storage, removing all items from the underlying storage client.
This method does not remove the storage itself, e.g. don't remove the metadata,
but clears all items within it.
"""