memory-foam 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- memory_foam/__init__.py +17 -0
- memory_foam/asyn.py +36 -0
- memory_foam/client/__init__.py +3 -0
- memory_foam/client/fsspec.py +137 -0
- memory_foam/client/s3.py +143 -0
- memory_foam/file.py +28 -0
- memory_foam-0.0.1.dist-info/LICENSE +201 -0
- memory_foam-0.0.1.dist-info/METADATA +70 -0
- memory_foam-0.0.1.dist-info/RECORD +11 -0
- memory_foam-0.0.1.dist-info/WHEEL +5 -0
- memory_foam-0.0.1.dist-info/top_level.txt +1 -0
memory_foam/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Iterator, Optional
|
|
2
|
+
from .client import Client
|
|
3
|
+
|
|
4
|
+
from .file import File, FilePointer
|
|
5
|
+
from .asyn import iter_over_async, get_loop
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def iter_files(uri: str, client_config: Optional[dict]) -> Iterator[File]:
|
|
9
|
+
config = client_config or {}
|
|
10
|
+
client = Client.get_client(uri, **config)
|
|
11
|
+
_, path = client.parse_url(uri)
|
|
12
|
+
for file in iter_over_async(client.iter_files(path.rstrip("/")), get_loop()):
|
|
13
|
+
yield file
|
|
14
|
+
client.close()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__all__ = ["iter_files", "File", "FilePointer"]
|
memory_foam/asyn.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from fsspec.asyn import get_loop
|
|
4
|
+
from typing import AsyncIterable, Awaitable, Iterator, TypeVar
|
|
5
|
+
|
|
6
|
+
T = TypeVar("T")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def queue_task_result(coro: Awaitable[T], queue: asyncio.Queue, loop=get_loop()):
|
|
10
|
+
task = asyncio.ensure_future(coro, loop=loop)
|
|
11
|
+
result = await task
|
|
12
|
+
await queue.put(result)
|
|
13
|
+
return task
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def iter_over_async(
|
|
17
|
+
ait: AsyncIterable[T], loop: asyncio.AbstractEventLoop
|
|
18
|
+
) -> Iterator[T]:
|
|
19
|
+
"""Wrap an asynchronous iterator into a synchronous one"""
|
|
20
|
+
|
|
21
|
+
ait = ait.__aiter__()
|
|
22
|
+
|
|
23
|
+
# helper async fn that just gets the next element from the async iterator
|
|
24
|
+
async def get_next():
|
|
25
|
+
try:
|
|
26
|
+
obj = await ait.__anext__()
|
|
27
|
+
return False, obj
|
|
28
|
+
except StopAsyncIteration:
|
|
29
|
+
return True, None
|
|
30
|
+
|
|
31
|
+
# actual sync iterator
|
|
32
|
+
while True:
|
|
33
|
+
done, obj = asyncio.run_coroutine_threadsafe(get_next(), loop).result()
|
|
34
|
+
if done:
|
|
35
|
+
break
|
|
36
|
+
yield obj
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
import asyncio
|
|
3
|
+
import multiprocessing
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any, AsyncIterator, ClassVar, Optional
|
|
6
|
+
from fsspec.spec import AbstractFileSystem
|
|
7
|
+
from urllib.parse import urlparse
|
|
8
|
+
|
|
9
|
+
from ..file import File
|
|
10
|
+
from ..asyn import get_loop
|
|
11
|
+
|
|
12
|
+
DELIMITER = "/" # Path delimiter.
|
|
13
|
+
FETCH_WORKERS = 100
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# need to move to a new file
|
|
17
|
+
|
|
18
|
+
ResultQueue = asyncio.Queue[Optional[File]]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ClientError(RuntimeError):
|
|
22
|
+
def __init__(self, message, error_code=None):
|
|
23
|
+
super().__init__(message)
|
|
24
|
+
# error code from the cloud itself
|
|
25
|
+
self.error_code = error_code
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Client(ABC):
|
|
29
|
+
MAX_THREADS = multiprocessing.cpu_count()
|
|
30
|
+
FS_CLASS: ClassVar[AbstractFileSystem]
|
|
31
|
+
PREFIX: ClassVar[str]
|
|
32
|
+
protocol: ClassVar[str]
|
|
33
|
+
|
|
34
|
+
def __init__(self, name: str, fs_kwargs: dict[str, Any]) -> None:
|
|
35
|
+
self.name = name
|
|
36
|
+
self.fs_kwargs = fs_kwargs
|
|
37
|
+
self._fs: Optional[AbstractFileSystem] = None
|
|
38
|
+
self.uri = self.get_uri(self.name)
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def create_fs(cls, **kwargs) -> "AbstractFileSystem":
|
|
42
|
+
kwargs.setdefault("version_aware", True)
|
|
43
|
+
fs = cls.FS_CLASS(**kwargs)
|
|
44
|
+
fs.invalidate_cache()
|
|
45
|
+
return fs
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def close(self) -> None: ...
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def fs(self) -> AbstractFileSystem:
|
|
52
|
+
if not self._fs:
|
|
53
|
+
self._fs = self.create_fs(**self.fs_kwargs)
|
|
54
|
+
return self._fs
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def get_implementation(url: str) -> type["Client"]:
|
|
58
|
+
# from .azure import AzureClient
|
|
59
|
+
# from .gcs import GCSClient
|
|
60
|
+
from .s3 import ClientS3
|
|
61
|
+
|
|
62
|
+
protocol = urlparse(url).scheme
|
|
63
|
+
|
|
64
|
+
if not protocol:
|
|
65
|
+
raise NotImplementedError(
|
|
66
|
+
"Unsupported protocol: urlparse was not able to identify a scheme"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
protocol = protocol.lower()
|
|
70
|
+
if protocol == ClientS3.protocol:
|
|
71
|
+
return ClientS3
|
|
72
|
+
# if protocol == GCSClient.protocol:
|
|
73
|
+
# return GCSClient
|
|
74
|
+
# if protocol == AzureClient.protocol:
|
|
75
|
+
# return AzureClient
|
|
76
|
+
|
|
77
|
+
raise NotImplementedError(f"Unsupported protocol: {protocol}")
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def get_client(source: str, **kwargs) -> "Client":
|
|
81
|
+
cls = Client.get_implementation(source)
|
|
82
|
+
storage_url, _ = cls.split_url(source)
|
|
83
|
+
if os.name == "nt":
|
|
84
|
+
storage_url = storage_url.removeprefix("/")
|
|
85
|
+
|
|
86
|
+
return cls.from_name(storage_url, kwargs)
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def from_name(
|
|
90
|
+
cls,
|
|
91
|
+
name: str,
|
|
92
|
+
kwargs: dict[str, Any],
|
|
93
|
+
) -> "Client":
|
|
94
|
+
return cls(name, kwargs)
|
|
95
|
+
|
|
96
|
+
def parse_url(self, source: str) -> tuple[str, str]:
|
|
97
|
+
storage_name, rel_path = self.split_url(source)
|
|
98
|
+
return self.get_uri(storage_name), rel_path
|
|
99
|
+
|
|
100
|
+
def get_uri(self, name: str) -> str:
|
|
101
|
+
return f"{self.PREFIX}{name}"
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def split_url(self, url: str) -> tuple[str, str]:
|
|
105
|
+
fill_path = url[len(self.PREFIX) :]
|
|
106
|
+
path_split = fill_path.split("/", 1)
|
|
107
|
+
bucket = path_split[0]
|
|
108
|
+
path = path_split[1] if len(path_split) > 1 else ""
|
|
109
|
+
return bucket, path
|
|
110
|
+
|
|
111
|
+
def get_full_path(self, rel_path: str, version_id: Optional[str] = None) -> str:
|
|
112
|
+
return self.version_path(f"{self.PREFIX}{self.name}/{rel_path}", version_id)
|
|
113
|
+
|
|
114
|
+
def version_path(cls, path: str, version_id: Optional[str]) -> str:
|
|
115
|
+
return path
|
|
116
|
+
|
|
117
|
+
async def iter_files(self, start_prefix: str) -> AsyncIterator[File]:
|
|
118
|
+
result_queue: ResultQueue = asyncio.Queue(200)
|
|
119
|
+
loop = get_loop()
|
|
120
|
+
main_task = loop.create_task(self._fetch(start_prefix, result_queue))
|
|
121
|
+
|
|
122
|
+
while (file := await result_queue.get()) is not None:
|
|
123
|
+
yield file
|
|
124
|
+
|
|
125
|
+
await main_task
|
|
126
|
+
|
|
127
|
+
@abstractmethod
|
|
128
|
+
async def _fetch(self, start_prefix: str, result_queue: ResultQueue) -> None: ...
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def _is_valid_key(key: str) -> bool:
|
|
132
|
+
"""
|
|
133
|
+
Check if the key looks like a valid path.
|
|
134
|
+
|
|
135
|
+
Invalid keys are ignored when indexing.
|
|
136
|
+
"""
|
|
137
|
+
return not (key.startswith("/") or key.endswith("/") or "//" in key)
|
memory_foam/client/s3.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Any, Optional, cast
|
|
3
|
+
from s3fs import S3FileSystem
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from ..asyn import queue_task_result, get_loop
|
|
7
|
+
from ..file import File, FilePointer
|
|
8
|
+
from .fsspec import DELIMITER, Client, ResultQueue
|
|
9
|
+
|
|
10
|
+
from botocore.exceptions import NoCredentialsError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ClientS3(Client):
|
|
14
|
+
FS_CLASS = S3FileSystem
|
|
15
|
+
PREFIX = "s3://"
|
|
16
|
+
protocol = "s3"
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def create_fs(cls, **kwargs) -> S3FileSystem:
|
|
20
|
+
if "aws_endpoint_url" in kwargs:
|
|
21
|
+
kwargs.setdefault("client_kwargs", {}).setdefault(
|
|
22
|
+
"endpoint_url", kwargs.pop("aws_endpoint_url")
|
|
23
|
+
)
|
|
24
|
+
if "aws_key" in kwargs:
|
|
25
|
+
kwargs.setdefault("key", kwargs.pop("aws_key"))
|
|
26
|
+
if "aws_secret" in kwargs:
|
|
27
|
+
kwargs.setdefault("secret", kwargs.pop("aws_secret"))
|
|
28
|
+
if "aws_token" in kwargs:
|
|
29
|
+
kwargs.setdefault("token", kwargs.pop("aws_token"))
|
|
30
|
+
|
|
31
|
+
# We want to use newer v4 signature version since regions added after
|
|
32
|
+
# 2014 are not going to support v2 which is the older one.
|
|
33
|
+
# All regions support v4.
|
|
34
|
+
kwargs.setdefault("config_kwargs", {}).setdefault("signature_version", "s3v4")
|
|
35
|
+
|
|
36
|
+
if "region_name" in kwargs:
|
|
37
|
+
kwargs["config_kwargs"].setdefault("region_name", kwargs.pop("region_name"))
|
|
38
|
+
if not kwargs.get("anon"):
|
|
39
|
+
try:
|
|
40
|
+
# Run an inexpensive check to see if credentials are available
|
|
41
|
+
super().create_fs(**kwargs).sign("s3://bucket/object")
|
|
42
|
+
except NoCredentialsError:
|
|
43
|
+
kwargs["anon"] = True
|
|
44
|
+
except NotImplementedError:
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
return cast(S3FileSystem, super().create_fs(**kwargs, asynchronous=True))
|
|
48
|
+
|
|
49
|
+
def close(self):
|
|
50
|
+
self.fs.close_session(get_loop(), self.s3)
|
|
51
|
+
|
|
52
|
+
async def _fetch(self, start_prefix: str, result_queue: ResultQueue) -> None:
|
|
53
|
+
loop = get_loop()
|
|
54
|
+
|
|
55
|
+
async def get_pages(it, page_queue):
|
|
56
|
+
try:
|
|
57
|
+
async for page in it:
|
|
58
|
+
await page_queue.put(page.get(contents_key, []))
|
|
59
|
+
finally:
|
|
60
|
+
await page_queue.put(None)
|
|
61
|
+
|
|
62
|
+
async def process_pages(page_queue, result_queue):
|
|
63
|
+
max_concurrent_reads = asyncio.Semaphore(32)
|
|
64
|
+
|
|
65
|
+
async def _read_file(pointer: FilePointer) -> File:
|
|
66
|
+
async with max_concurrent_reads:
|
|
67
|
+
contents = await self._read(pointer.path, pointer.version)
|
|
68
|
+
return (pointer, contents)
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
found = False
|
|
72
|
+
|
|
73
|
+
while (res := await page_queue.get()) is not None:
|
|
74
|
+
if res:
|
|
75
|
+
found = True
|
|
76
|
+
|
|
77
|
+
tasks = []
|
|
78
|
+
for d in res:
|
|
79
|
+
if not self._is_valid_key(d["Key"]):
|
|
80
|
+
continue
|
|
81
|
+
pointer = self._info_to_file_pointer(d)
|
|
82
|
+
task = queue_task_result(
|
|
83
|
+
_read_file(pointer), result_queue, loop
|
|
84
|
+
)
|
|
85
|
+
tasks.append(task)
|
|
86
|
+
await asyncio.gather(*tasks)
|
|
87
|
+
|
|
88
|
+
if not found:
|
|
89
|
+
raise FileNotFoundError(f"Unable to resolve remote path: {prefix}")
|
|
90
|
+
finally:
|
|
91
|
+
await result_queue.put(None)
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
prefix = start_prefix
|
|
95
|
+
if prefix:
|
|
96
|
+
prefix = prefix.lstrip(DELIMITER) + DELIMITER
|
|
97
|
+
versions = True
|
|
98
|
+
fs = self.fs
|
|
99
|
+
await fs.set_session()
|
|
100
|
+
self.s3 = await fs.get_s3(self.name)
|
|
101
|
+
if versions:
|
|
102
|
+
method = "list_object_versions"
|
|
103
|
+
contents_key = "Versions"
|
|
104
|
+
else:
|
|
105
|
+
method = "list_objects_v2"
|
|
106
|
+
contents_key = "Contents"
|
|
107
|
+
pag = self.s3.get_paginator(method)
|
|
108
|
+
it = pag.paginate(
|
|
109
|
+
Bucket=self.name,
|
|
110
|
+
Prefix=prefix,
|
|
111
|
+
Delimiter="",
|
|
112
|
+
)
|
|
113
|
+
page_queue: ResultQueue = asyncio.Queue(2)
|
|
114
|
+
page_consumer = loop.create_task(process_pages(page_queue, result_queue))
|
|
115
|
+
try:
|
|
116
|
+
await get_pages(it, page_queue)
|
|
117
|
+
await page_consumer
|
|
118
|
+
finally:
|
|
119
|
+
page_consumer.cancel() # In case get_pages() raised
|
|
120
|
+
finally:
|
|
121
|
+
result_queue.put_nowait(None)
|
|
122
|
+
|
|
123
|
+
async def _read(self, path, version) -> bytes:
|
|
124
|
+
stream = await self.fs.open_async(self.get_full_path(path, version))
|
|
125
|
+
return await stream.read()
|
|
126
|
+
|
|
127
|
+
def _info_to_file_pointer(
|
|
128
|
+
self,
|
|
129
|
+
v: dict[str, Any],
|
|
130
|
+
) -> FilePointer:
|
|
131
|
+
version = self._clean_s3_version(v.get("VersionId", ""))
|
|
132
|
+
return FilePointer(
|
|
133
|
+
source=self.uri,
|
|
134
|
+
path=v["Key"],
|
|
135
|
+
size=v["Size"],
|
|
136
|
+
version=version,
|
|
137
|
+
last_modified=v.get("LastModified", ""),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
def _clean_s3_version(self, ver: Optional[str]) -> str:
|
|
141
|
+
if ver is None or ver == "null":
|
|
142
|
+
return ""
|
|
143
|
+
return ver
|
memory_foam/file.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from dataclasses import asdict, dataclass
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass
|
|
6
|
+
class FilePointer:
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
Attributes:
|
|
10
|
+
source (str): The source of the file (e.g., 's3://bucket-name/').
|
|
11
|
+
path (str): The path to the file (e.g., 'path/to/file.txt').
|
|
12
|
+
size (int): The size of the file in bytes. Defaults to 0.
|
|
13
|
+
version (str): The version of the file. Defaults to an empty string.
|
|
14
|
+
last_modified (datetime): The last modified timestamp of the file.
|
|
15
|
+
Defaults to Unix epoch (`1970-01-01T00:00:00`).
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
source: str
|
|
19
|
+
path: str
|
|
20
|
+
size: int
|
|
21
|
+
version: str
|
|
22
|
+
last_modified: datetime
|
|
23
|
+
|
|
24
|
+
def to_dict_with(self, d: dict):
|
|
25
|
+
return {**asdict(self), **d}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
File = tuple[FilePointer, bytes]
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: memory-foam
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Read the contents of files from S3, GCS and Azure into memory
|
|
5
|
+
Author-email: Matt Seddon <mattseddon@hotmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Documentation, https://github.com/mattseddon/memory-foam
|
|
8
|
+
Project-URL: Issues, https://github.com/mattseddon/memory-foam/issues
|
|
9
|
+
Project-URL: Source, https://github.com/mattseddon/memory-foam
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: fsspec>=2024.2.0
|
|
21
|
+
Requires-Dist: s3fs>=2024.2.0
|
|
22
|
+
Requires-Dist: gcsfs>=2024.2.0
|
|
23
|
+
Requires-Dist: adlfs>=2024.2.0
|
|
24
|
+
Provides-Extra: tests
|
|
25
|
+
Requires-Dist: pytest<9,>=8; extra == "tests"
|
|
26
|
+
Requires-Dist: pytest-sugar>=0.9.6; extra == "tests"
|
|
27
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "tests"
|
|
28
|
+
Requires-Dist: pytest-mock>=3.12.0; extra == "tests"
|
|
29
|
+
Requires-Dist: pytest-servers[all]>=0.5.9; extra == "tests"
|
|
30
|
+
Requires-Dist: hypothesis; extra == "tests"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: memory_foam[tests]; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy==1.15.0; extra == "dev"
|
|
34
|
+
Provides-Extra: examples
|
|
35
|
+
Requires-Dist: dlt; extra == "examples"
|
|
36
|
+
Requires-Dist: pillow; extra == "examples"
|
|
37
|
+
Requires-Dist: ultralytics; extra == "examples"
|
|
38
|
+
Requires-Dist: tqdm; extra == "examples"
|
|
39
|
+
|
|
40
|
+
# memory-foam
|
|
41
|
+
|
|
42
|
+
`memory-foam` is a Python package that provides a set of iterators to load the contents of files from s3 cloud storage into memory for easy processing.
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Unified Interface**: Seamlessly interact with files stored in S3.
|
|
47
|
+
- **Asynchronous Support**: Efficiently load files using asynchronous iterators.
|
|
48
|
+
- **Version Awareness**: Handle different versions of files with ease.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
You can install `memory-foam` using pip:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install memory-foam
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Example usage
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from io import BytesIO
|
|
62
|
+
from memory_foam import iter_files
|
|
63
|
+
|
|
64
|
+
...
|
|
65
|
+
|
|
66
|
+
for pointer, contents in iter_files(uri, client_config):
|
|
67
|
+
results = process(contents)
|
|
68
|
+
data = pointer.to_dict_with(results)
|
|
69
|
+
save(data)
|
|
70
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
memory_foam/__init__.py,sha256=Jez51Vz7auM2yPCoPdNyCBte3HlgXRYePWMulInQk5M,508
|
|
2
|
+
memory_foam/asyn.py,sha256=rK4NHZtQrBvqB7CDZLBGeJWow8WDjLz-KJM1ezGCmRY,958
|
|
3
|
+
memory_foam/file.py,sha256=OIQfzGTW45W5ipHDTswsHFkU34y1HqvPopIxjNKCjLs,758
|
|
4
|
+
memory_foam/client/__init__.py,sha256=1kDpCPoibMXi1gExR4lTLc5pi-k6M5TANiwtXkPoLhU,49
|
|
5
|
+
memory_foam/client/fsspec.py,sha256=Y7uNtyLfgasfoLJwZgbCwqbWs8BHu6n6kmqTRwxJcR0,4101
|
|
6
|
+
memory_foam/client/s3.py,sha256=jARW-Vl0rGMOIvhLgvEcMJmzSYWlbS9CAYfOg5FitWc,5065
|
|
7
|
+
memory_foam-0.0.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
8
|
+
memory_foam-0.0.1.dist-info/METADATA,sha256=vWnqnBbx3ycBboUGcQ-TlmaKhIFff0ZmXtTPy9ZTGxk,2353
|
|
9
|
+
memory_foam-0.0.1.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
10
|
+
memory_foam-0.0.1.dist-info/top_level.txt,sha256=IRXnv-MLhKDovxOG2qhklYTdeA3T0GqYVDgLQjsUA-I,12
|
|
11
|
+
memory_foam-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
memory_foam
|