Repository navigation
feat(sdk): add dfcache Python SDK - #2148
Open
hock1024always wants to merge 4 commits into
Open
hock1024always wants to merge 4 commits into
hock1024always wants to merge 4 commits into
Conversation
Implement the dfcache Python SDK for issue dragonflyoss/dragonfly#4422, targeting AI developers that share models, datasets and checkpoints across nodes through the Dragonfly P2P persistent cache. The SDK wraps the dfdaemon download/upload gRPC services over the unix domain socket (default /var/run/dragonfly/dfdaemon.sock) using the existing dragonfly-api PyPI bindings, mirroring the dfcache CLI: * import_file - dfcache import (UploadPersistentCacheTask) * export_file - dfcache export (DownloadPersistentCacheTask) * stat - dfcache stat (StatPersistentCacheTask) * delete - exposed by the proto, missing from the CLI (DeletePersistentCacheTask on the upload service) Client-side validation mirrors the CLI rules (ttl 5m-7d, replica count 1-5, piece length >= 4MiB, digest format). gRPC errors surface as typed exceptions; failed exports remove the partial output file. The test suite runs against an in-process fake dfdaemon over a real unix socket. Signed-off-by: hock1024always <hock1024always@users.noreply.github.com>
hock1024always
requested review from
BruceAko,
CooooolFrog,
gaius-qi,
hhhhsdxxxx and
yxxhero
November 9, 2026 04:07
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2148 +/- ##
==========================================
- Coverage 65.75% 65.16% -0.59%
==========================================
Files 102 108 +6
Lines 31270 31745 +475
==========================================
+ Hits 20561 20688 +127
- Misses 10709 11057 +348
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Python 3.9 is not available for x64 on ubuntu-latest (26.04), pin the runner to ubuntu-24.04 so the full 3.9-3.12 matrix runs. Signed-off-by: hock1024always <hoc***@users.noreply.github.com>
…uds authority Two issues found while testing the SDK against a locally built dfdaemon: 1. DeletePersistentCacheTask is served by the dfdaemon upload gRPC server, which listens on TCP (default port 4000); the download unix domain socket only hosts the download service. Calling delete through the download socket returned UNIMPLEMENTED against the real daemon. The client now opens a second channel to the upload service, with an upload_endpoint parameter defaulting to 127.0.0.1:4000. The test fake mirrors the real topology: download over the unix socket, upload over TCP. 2. grpc-python over a unix domain socket derives the http/2 :authority header from the percent-encoded socket path (e.g. tmp%2Fdragonfly%2Fdfdaemon.sock). Server stacks using h2 >= 0.4 reject it as a malformed authority and reset the stream, so every RPC died with RST_STREAM PROTOCOL_ERROR. The channel is now created with an explicit grpc.default_authority option. Validated end to end against a locally built dfdaemon backed by a fake scheduler: import, stat (ttl/replicas), digest-verified export, wrong digest failure with output cleanup, delete and post-delete export failure. Also adds a --reference integrity flag to the example. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: hock1024always <hock1024always@users.noreply.github.com>
hock1024always
force-pushed
the
feat/dfcache-python-sdk
branch
from
November 9, 2026 08:43
30540fc to
94431dc
Compare
AsyncDfcacheClient mirrors the sync DfcacheClient surface with async def methods on grpc.aio channels, for callers already running an event loop (training jobs, notebooks, FastAPI handlers). The download response stream is consumed with async for; the preferred-local-ip probe runs off the loop thread via run_in_executor. Co-Authored-By: Claude <nore***@anthropic.com> Signed-off-by: hock1024always <hoc***@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Implement the dfcache Python SDK for dragonflyoss/dragonfly#4422, targeting AI developers that share models, datasets and checkpoints across nodes through the Dragonfly P2P persistent cache.
The SDK wraps the dfdaemon download/upload gRPC services over the unix domain socket (default
/var/run/dragonfly/dfdaemon.sock) using the existing dragonfly-api PyPI bindings (generated from dragonflyoss/api), mirroring the dfcache CLI — no Rust code is required:client.import_file(path, ...)dfcache import→DfdaemonDownload/UploadPersistentCacheTaskclient.export_file(task_id, output=..., ...)dfcache export→DfdaemonDownload/DownloadPersistentCacheTaskclient.stat(task_id)dfcache stat→DfdaemonDownload/StatPersistentCacheTaskclient.delete(task_id)DfdaemonUpload/DeletePersistentCacheTaskDesign decisions
AsyncDfcacheClientcan follow later. The client is thread-safe (shared gRPC channel).<algorithm>:<hash>digest format) so users get immediate actionable errors.DfcacheTaskNotFoundError,DfcachePermissionDeniedError(blocklist),DfcacheConnectionError, etc., all deriving fromDfcacheError.Layout
CI: a new
python-sdk.ymlworkflow runs the suite on Python 3.9–3.12 with codecov (flags: python-sdk).Questions for maintainers (also posted in the issue)
sdks/python/in this repo the right home, or would a separate repo be preferred?dragonfly-cache? (avoiding confusion with the Redis-compatibledragonflydb)Related Issue
Fixes #4422 (dragonflyoss/dragonfly)
🤖 Generated with Claude Code