-
Notifications
You must be signed in to change notification settings - Fork 416
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 26 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
21 changes: 0 additions & 21 deletions
21
docs/guides/code_examples/storages/cleaning_purge_explicitly_example.py
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
id: upgrading-to-v1 | ||
title: Upgrading to v1 | ||
--- | ||
|
||
This page summarizes the breaking changes between Crawlee for Python v0.6 and v1.0. | ||
|
||
## Storage clients | ||
|
||
In v1.0, we are introducing a new storage clients system. We have completely reworked their interface, | ||
making it much simpler to write your own storage clients. This allows you to easily store your request queues, | ||
key-value stores, and datasets in various destinations. | ||
|
||
### New storage clients | ||
|
||
Previously, the `MemoryStorageClient` handled both in-memory storage and file system persistence, depending | ||
on configuration. In v1.0, we've split this into two dedicated classes: | ||
|
||
- `MemoryStorageClient` - stores all data in memory only. | ||
- `FileSystemStorageClient` - persists data on the file system, with in-memory caching for improved performance. | ||
|
||
For details about the new interface, see the `BaseStorageClient` documentation. You can also check out | ||
the [Storage clients guide](https://crawlee.dev/python/docs/guides/) for more information on available | ||
storage clients and instructions on writing your own. | ||
|
||
### Memory storage client | ||
|
||
Before: | ||
|
||
```python | ||
from crawlee.configuration import Configuration | ||
from crawlee.storage_clients import MemoryStorageClient | ||
|
||
configuration = Configuration(persist_storage=False) | ||
storage_client = MemoryStorageClient.from_config(configuration) | ||
``` | ||
|
||
Now: | ||
|
||
```python | ||
from crawlee.storage_clients import MemoryStorageClient | ||
|
||
storage_client = MemoryStorageClient() | ||
``` | ||
|
||
### File-system storage client | ||
|
||
Before: | ||
|
||
```python | ||
from crawlee.configuration import Configuration | ||
from crawlee.storage_clients import MemoryStorageClient | ||
|
||
configuration = Configuration(persist_storage=True) | ||
storage_client = MemoryStorageClient.from_config(configuration) | ||
``` | ||
|
||
Now: | ||
|
||
```python | ||
from crawlee.storage_clients import FileSystemStorageClient | ||
|
||
storage_client = FileSystemStorageClient() | ||
``` | ||
|
||
The way you register storage clients remains the same: | ||
|
||
```python | ||
from crawlee import service_locator | ||
from crawlee.crawlers import ParselCrawler | ||
from crawlee.storage_clients import MemoryStorageClient | ||
|
||
storage_client = MemoryStorageClient() | ||
|
||
# Either via the service locator: | ||
service_locator.set_storage_client(storage_client) | ||
|
||
# Or provide it directly to the crawler: | ||
crawler = ParselCrawler(storage_client=storage_client) | ||
``` | ||
|
||
### Breaking changes | ||
vdusek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The `persist_storage` and `persist_metadata` fields have been removed from the `Configuration` class. | ||
Persistence is now determined solely by the storage client class you use. | ||
|
||
### Writing custom storage clients | ||
|
||
The storage client interface has been fully reworked. Collection storage clients have been removed - now there is | ||
one storage client class per storage type (`RequestQueue`, `KeyValueStore`, and `Dataset`). Writing your own storage | ||
clients is now much simpler, allowing you to store your request queues, key-value stores, and datasets in any | ||
destination you choose. | ||
|
||
## Dataset | ||
|
||
- There are two new methods: | ||
- `purge` | ||
- `list_items` | ||
- The `from_storage_object` method has been removed - use the `open` method with `name` or `id` instead. | ||
- The `get_info` and `storage_object` properties have been replaced by the new `metadata` property. | ||
- The `set_metadata` method has been removed. | ||
- The `write_to_json` and `write_to_csv` methods have been removed - use `export_to` instead. | ||
|
||
## Key-value store | ||
|
||
- There are three new methods: | ||
- `purge` | ||
- `delete_value` | ||
- `list_keys` | ||
- The `from_storage_object` method has been removed - use the `open` method with `name` or `id` instead. | ||
- The `get_info` and `storage_object` properties have been replaced by the new `metadata` property. | ||
- The `set_metadata` method has been removed. | ||
|
||
## Request queue | ||
|
||
- There are two new methods: | ||
- `purge` | ||
- `add_requests` (renamed from `add_requests_batched`) | ||
- The `from_storage_object` method has been removed - use the `open` method with `name` or `id` instead. | ||
- The `get_info` and `storage_object` properties have been replaced by the new `metadata` property. | ||
- The `set_metadata` method has been removed. | ||
- `resource_directory` from `RequestQueueMetadata` removed – use `path_to_...` property. | ||
- `RequestQueueHead` model replaced with `RequestQueueHeadWithLocks`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from __future__ import annotations | ||
|
||
METADATA_FILENAME = '__metadata__.json' | ||
"""The name of the metadata file for storage clients.""" |
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.
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.