-
Notifications
You must be signed in to change notification settings - Fork 425
refactor!: Introduce new storage client system #1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
f285707
refactor!: Introduce new storage client system
vdusek dd9be6e
Cleanup
vdusek 89bfa5b
Address feedback
vdusek 4050c75
Add purge_if_needed method and improve some typing based on Pylance
vdusek 26f46e2
Address more feedback
vdusek c83a36a
RQ FS client improvements
vdusek c967fe5
Add caching to RQ FS client
vdusek 7df046f
RQ FS performance optimization in add_requests
vdusek 3555565
RQ FS performance issues in fetch_next_request
vdusek 946d1e2
RQ FS fetch performance for is_empty
vdusek 9f10b95
rm code duplication for open methods
vdusek 0864ff8
Request loaders use async getters for handled/total req cnt
vdusek af0d129
Add missing_ok when removing files
vdusek 9998a58
Improve is_empty
vdusek fdee111
Optimize RQ memory storage client
vdusek 79cdfc0
Add upgrading guide and skip problematic test
vdusek 3d2fd73
Merge branch 'master' into new-storage-clients
vdusek e818585
chore: update `docusaurus-plugin-typedoc-api`, fix failing docs build
barjin 65db9ac
fix docs
vdusek 2b786f7
add retries to atomic write
vdusek 2cb04c5
chore(deps): update dependency pytest-cov to ~=6.2.0 (#1244)
renovate[bot] 0c8c4ec
Fix atomic write on Windows
vdusek ce1eeb1
resolve write function during import time
vdusek 4c05cee
Merge branch 'master' into new-storage-clients
vdusek 8c80513
Update file utils
vdusek 70bc071
revert un-intentionally makefile changes
vdusek 78efb4d
Address Honza's comments (p1)
vdusek fa18d19
Introduce storage instance manager
vdusek c783dac
Utilize recoverable state for the FS RQ state
vdusek 437071e
Details
vdusek df4bfa7
Rm default_"storage"_id options (were not used at all)
vdusek e133fcd
Update storages guide and add storage clients guide
vdusek 76f1ffb
Docs guides - code examples
vdusek fa48644
Docs guides polishment
vdusek 5c935af
docs fix lint & type checks for py 3.9
vdusek ac259ce
Address Honza's feedback
vdusek 1cbf15e
SDK fixes
vdusek bc50990
Add KVS record_exists method
vdusek d1cf967
reduce test duplicities for storages & storage clients
vdusek aa9bfd3
Create locks in async context only
vdusek d6c9877
rm open methods from base storage clients
vdusek 3b133ce
update storage clients inits
vdusek 43b9fe9
async metadata getter
vdusek b628fbb
better typing in storage instance manager
vdusek 9dfac4b
update upgrading guide
vdusek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
docs/guides/code_examples/storage_clients/custom_storage_client_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from crawlee.storage_clients import StorageClient | ||
from crawlee.storage_clients._base import ( | ||
DatasetClient, | ||
KeyValueStoreClient, | ||
RequestQueueClient, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from crawlee.configuration import Configuration | ||
|
||
# Implement the storage type clients with your backend logic. | ||
|
||
|
||
class CustomDatasetClient(DatasetClient): | ||
# Implement methods like push_data, get_data, iterate_items, etc. | ||
pass | ||
|
||
|
||
class CustomKeyValueStoreClient(KeyValueStoreClient): | ||
# Implement methods like get_value, set_value, delete, etc. | ||
pass | ||
|
||
|
||
class CustomRequestQueueClient(RequestQueueClient): | ||
# Implement methods like add_request, fetch_next_request, etc. | ||
pass | ||
|
||
|
||
# Implement the storage client factory. | ||
|
||
|
||
class CustomStorageClient(StorageClient): | ||
async def create_dataset_client( | ||
self, | ||
*, | ||
id: str | None = None, | ||
name: str | None = None, | ||
configuration: Configuration | None = None, | ||
) -> CustomDatasetClient: | ||
# Create and return your custom dataset client. | ||
pass | ||
|
||
async def create_kvs_client( | ||
self, | ||
*, | ||
id: str | None = None, | ||
name: str | None = None, | ||
configuration: Configuration | None = None, | ||
) -> CustomKeyValueStoreClient: | ||
# Create and return your custom key-value store client. | ||
pass | ||
|
||
async def create_rq_client( | ||
self, | ||
*, | ||
id: str | None = None, | ||
name: str | None = None, | ||
configuration: Configuration | None = None, | ||
) -> CustomRequestQueueClient: | ||
# Create and return your custom request queue client. | ||
pass |
8 changes: 8 additions & 0 deletions
8
docs/guides/code_examples/storage_clients/file_system_storage_client_basic_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from crawlee.crawlers import ParselCrawler | ||
from crawlee.storage_clients import FileSystemStorageClient | ||
|
||
# Create a new instance of storage client. | ||
storage_client = FileSystemStorageClient() | ||
|
||
# And pass it to the crawler. | ||
crawler = ParselCrawler(storage_client=storage_client) |
18 changes: 18 additions & 0 deletions
18
.../guides/code_examples/storage_clients/file_system_storage_client_configuration_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from crawlee.configuration import Configuration | ||
from crawlee.crawlers import ParselCrawler | ||
from crawlee.storage_clients import FileSystemStorageClient | ||
|
||
# Create a new instance of storage client. | ||
storage_client = FileSystemStorageClient() | ||
|
||
# Create a configuration with custom settings. | ||
configuration = Configuration( | ||
storage_dir='./my_storage', | ||
purge_on_start=False, | ||
) | ||
|
||
# And pass them to the crawler. | ||
crawler = ParselCrawler( | ||
storage_client=storage_client, | ||
configuration=configuration, | ||
) |
8 changes: 8 additions & 0 deletions
8
docs/guides/code_examples/storage_clients/memory_storage_client_basic_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from crawlee.crawlers import ParselCrawler | ||
from crawlee.storage_clients import MemoryStorageClient | ||
|
||
# Create a new instance of storage client. | ||
storage_client = MemoryStorageClient() | ||
|
||
# And pass it to the crawler. | ||
crawler = ParselCrawler(storage_client=storage_client) |
29 changes: 29 additions & 0 deletions
29
docs/guides/code_examples/storage_clients/registering_storage_client_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import asyncio | ||
|
||
from crawlee import service_locator | ||
from crawlee.crawlers import ParselCrawler | ||
from crawlee.storage_clients import MemoryStorageClient | ||
from crawlee.storages import Dataset | ||
|
||
|
||
async def main() -> None: | ||
# Create custom storage client, MemoryStorageClient for example. | ||
storage_client = MemoryStorageClient() | ||
|
||
# Register it globally via the service locator. | ||
service_locator.set_storage_client(storage_client) | ||
|
||
# Or pass it directly to the crawler, it will be registered globally | ||
# to the service locator under the hood. | ||
crawler = ParselCrawler(storage_client=storage_client) | ||
|
||
# Or just provide it when opening a storage (e.g. dataset), it will be used | ||
# for this storage only, not globally. | ||
dataset = await Dataset.open( | ||
name='my_dataset', | ||
storage_client=storage_client, | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
19 changes: 9 additions & 10 deletions
19
docs/guides/code_examples/storages/cleaning_purge_explicitly_example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.