antd 0.1.0__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.
Files changed (38) hide show
  1. antd/__init__.py +129 -0
  2. antd/_discover.py +132 -0
  3. antd/_grpc.py +825 -0
  4. antd/_proto/__init__.py +0 -0
  5. antd/_proto/antd/__init__.py +0 -0
  6. antd/_proto/antd/v1/__init__.py +0 -0
  7. antd/_proto/antd/v1/chunks_pb2.py +58 -0
  8. antd/_proto/antd/v1/chunks_pb2.pyi +83 -0
  9. antd/_proto/antd/v1/chunks_pb2_grpc.py +231 -0
  10. antd/_proto/antd/v1/common_pb2.py +45 -0
  11. antd/_proto/antd/v1/common_pb2.pyi +47 -0
  12. antd/_proto/antd/v1/common_pb2_grpc.py +24 -0
  13. antd/_proto/antd/v1/data_pb2.py +64 -0
  14. antd/_proto/antd/v1/data_pb2.pyi +113 -0
  15. antd/_proto/antd/v1/data_pb2_grpc.py +362 -0
  16. antd/_proto/antd/v1/events_pb2.py +41 -0
  17. antd/_proto/antd/v1/events_pb2.pyi +21 -0
  18. antd/_proto/antd/v1/events_pb2_grpc.py +97 -0
  19. antd/_proto/antd/v1/files_pb2.py +52 -0
  20. antd/_proto/antd/v1/files_pb2.pyi +72 -0
  21. antd/_proto/antd/v1/files_pb2_grpc.py +273 -0
  22. antd/_proto/antd/v1/health_pb2.py +41 -0
  23. antd/_proto/antd/v1/health_pb2.pyi +29 -0
  24. antd/_proto/antd/v1/health_pb2_grpc.py +97 -0
  25. antd/_proto/antd/v1/upload_pb2.py +56 -0
  26. antd/_proto/antd/v1/upload_pb2.pyi +95 -0
  27. antd/_proto/antd/v1/upload_pb2_grpc.py +236 -0
  28. antd/_proto/antd/v1/wallet_pb2.py +49 -0
  29. antd/_proto/antd/v1/wallet_pb2.pyi +37 -0
  30. antd/_proto/antd/v1/wallet_pb2_grpc.py +221 -0
  31. antd/_rest.py +861 -0
  32. antd/exceptions.py +75 -0
  33. antd/models.py +247 -0
  34. antd-0.1.0.dist-info/METADATA +226 -0
  35. antd-0.1.0.dist-info/RECORD +38 -0
  36. antd-0.1.0.dist-info/WHEEL +4 -0
  37. antd-0.1.0.dist-info/licenses/LICENSE-APACHE +201 -0
  38. antd-0.1.0.dist-info/licenses/LICENSE-MIT +21 -0
antd/__init__.py ADDED
@@ -0,0 +1,129 @@
1
+ """Python SDK for the antd daemon (Autonomi network).
2
+
3
+ Provides REST and gRPC clients with identical APIs.
4
+
5
+ Usage:
6
+ from antd import AntdClient
7
+ client = AntdClient() # REST by default
8
+ result = client.data_put_public(b"hello")
9
+ data = client.data_get_public(result.address)
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from importlib.metadata import PackageNotFoundError, version as _dist_version
15
+
16
+ try:
17
+ __version__ = _dist_version("antd")
18
+ except PackageNotFoundError: # running from a source checkout that is not installed
19
+ __version__ = "0.0.0"
20
+
21
+ from .models import (
22
+ CandidateNodeEntry,
23
+ DataPutPublicResult,
24
+ DataPutResult,
25
+ DownloadFrame,
26
+ DownloadProgress,
27
+ FilePutPublicResult,
28
+ FilePutResult,
29
+ FinalizeUploadResult,
30
+ HealthStatus,
31
+ PaymentInfo,
32
+ PaymentMode,
33
+ PoolCommitmentEntry,
34
+ PrepareChunkResult,
35
+ PrepareUploadResult,
36
+ PutResult,
37
+ UploadCostEstimate,
38
+ WalletAddress,
39
+ WalletBalance,
40
+ )
41
+ from ._discover import discover_daemon_url, discover_grpc_target
42
+ from .exceptions import (
43
+ AntdError,
44
+ AlreadyExistsError,
45
+ BadRequestError,
46
+ ForkError,
47
+ InternalError,
48
+ NetworkError,
49
+ NotFoundError,
50
+ PaymentError,
51
+ TooLargeError,
52
+ )
53
+
54
+ __all__ = [
55
+ "__version__",
56
+ # Discovery
57
+ "discover_daemon_url",
58
+ "discover_grpc_target",
59
+ # Factory functions
60
+ "AntdClient",
61
+ "AsyncAntdClient",
62
+ # Models
63
+ "CandidateNodeEntry",
64
+ "DataPutPublicResult",
65
+ "DataPutResult",
66
+ "DownloadFrame",
67
+ "DownloadProgress",
68
+ "FilePutPublicResult",
69
+ "FilePutResult",
70
+ "FinalizeUploadResult",
71
+ "HealthStatus",
72
+ "PaymentInfo",
73
+ "PaymentMode",
74
+ "PoolCommitmentEntry",
75
+ "PrepareChunkResult",
76
+ "PrepareUploadResult",
77
+ "PutResult",
78
+ "UploadCostEstimate",
79
+ "WalletAddress",
80
+ "WalletBalance",
81
+ # Exceptions
82
+ "AntdError",
83
+ "AlreadyExistsError",
84
+ "BadRequestError",
85
+ "ForkError",
86
+ "InternalError",
87
+ "NetworkError",
88
+ "NotFoundError",
89
+ "PaymentError",
90
+ "TooLargeError",
91
+ ]
92
+
93
+
94
+ def AntdClient(transport: str = "rest", **kwargs):
95
+ """Create a synchronous antd client.
96
+
97
+ Args:
98
+ transport: "rest" (default) or "grpc"
99
+ **kwargs: Passed to the underlying client constructor.
100
+ REST: base_url (default "http://localhost:8082"), timeout
101
+ gRPC: target (default "localhost:50051")
102
+ """
103
+ if transport == "rest":
104
+ from ._rest import RestClient
105
+ return RestClient(**kwargs)
106
+ elif transport == "grpc":
107
+ from ._grpc import GrpcClient
108
+ return GrpcClient(**kwargs)
109
+ else:
110
+ raise ValueError(f"Unknown transport: {transport!r}. Use 'rest' or 'grpc'.")
111
+
112
+
113
+ def AsyncAntdClient(transport: str = "rest", **kwargs):
114
+ """Create an asynchronous antd client.
115
+
116
+ Args:
117
+ transport: "rest" (default) or "grpc"
118
+ **kwargs: Passed to the underlying client constructor.
119
+ REST: base_url (default "http://localhost:8082"), timeout
120
+ gRPC: target (default "localhost:50051")
121
+ """
122
+ if transport == "rest":
123
+ from ._rest import AsyncRestClient
124
+ return AsyncRestClient(**kwargs)
125
+ elif transport == "grpc":
126
+ from ._grpc import AsyncGrpcClient
127
+ return AsyncGrpcClient(**kwargs)
128
+ else:
129
+ raise ValueError(f"Unknown transport: {transport!r}. Use 'rest' or 'grpc'.")
antd/_discover.py ADDED
@@ -0,0 +1,132 @@
1
+ """Daemon port-file discovery for antd.
2
+
3
+ The antd daemon writes a ``daemon.port`` file on startup containing:
4
+ - Line 1: REST port
5
+ - Line 2: gRPC port
6
+ - Line 3: PID of the daemon process (optional, for staleness detection)
7
+
8
+ This module reads that file to auto-discover the daemon's listen addresses.
9
+ If a PID is present and the process is no longer running, the port file is
10
+ considered stale and discovery returns empty results.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+ import sys
17
+ from pathlib import Path
18
+
19
+ _PORT_FILE_NAME = "daemon.port"
20
+ _DATA_DIR_NAME = "ant"
21
+ _SDK_SUBDIR_NAME = "sdk"
22
+
23
+
24
+ def discover_daemon_url() -> str:
25
+ """Return the REST base URL from the daemon port file, or ``""`` on failure."""
26
+ rest, _ = _read_port_file()
27
+ if rest == 0:
28
+ return ""
29
+ return f"http://127.0.0.1:{rest}"
30
+
31
+
32
+ def discover_grpc_target() -> str:
33
+ """Return the gRPC target from the daemon port file, or ``""`` on failure."""
34
+ _, grpc = _read_port_file()
35
+ if grpc == 0:
36
+ return ""
37
+ return f"127.0.0.1:{grpc}"
38
+
39
+
40
+ def _read_port_file() -> tuple[int, int]:
41
+ """Read the daemon.port file and return ``(rest_port, grpc_port)``.
42
+
43
+ A single-line file is valid (gRPC port will be 0).
44
+ Returns ``(0, 0)`` on any error.
45
+ """
46
+ dir_path = _data_dir()
47
+ if not dir_path:
48
+ return 0, 0
49
+
50
+ port_file = Path(dir_path) / _PORT_FILE_NAME
51
+ try:
52
+ text = port_file.read_text(encoding="utf-8")
53
+ except OSError:
54
+ return 0, 0
55
+
56
+ lines = text.strip().splitlines()
57
+ if not lines:
58
+ return 0, 0
59
+
60
+ # Check PID staleness (line 3, if present)
61
+ if len(lines) >= 3:
62
+ pid = _parse_pid(lines[2])
63
+ if pid is not None and not _is_process_alive(pid):
64
+ return 0, 0
65
+
66
+ rest_port = _parse_port(lines[0])
67
+ grpc_port = _parse_port(lines[1]) if len(lines) >= 2 else 0
68
+ return rest_port, grpc_port
69
+
70
+
71
+ def _parse_pid(s: str) -> int | None:
72
+ """Parse a PID string, returning ``None`` if absent or invalid."""
73
+ try:
74
+ n = int(s.strip())
75
+ except (ValueError, TypeError):
76
+ return None
77
+ if n > 0:
78
+ return n
79
+ return None
80
+
81
+
82
+ def _is_process_alive(pid: int) -> bool:
83
+ """Return ``True`` if a process with *pid* is currently running."""
84
+ try:
85
+ os.kill(pid, 0)
86
+ except ProcessLookupError:
87
+ return False
88
+ except PermissionError:
89
+ # Process exists but we lack permission to signal it — still alive.
90
+ return True
91
+ except OSError:
92
+ return False
93
+ return True
94
+
95
+
96
+ def _parse_port(s: str) -> int:
97
+ """Parse a port string, returning 0 on failure."""
98
+ try:
99
+ n = int(s.strip())
100
+ except (ValueError, TypeError):
101
+ return 0
102
+ if 1 <= n <= 65535:
103
+ return n
104
+ return 0
105
+
106
+
107
+ def _data_dir() -> str:
108
+ """Return the platform-specific data directory for the antd SDK daemon, or ``""``.
109
+
110
+ The ``sdk`` subdirectory keeps antd's port file separate from the
111
+ ant-node daemon, which writes to the same ``ant`` umbrella dir.
112
+ """
113
+ if sys.platform == "win32":
114
+ appdata = os.environ.get("APPDATA", "")
115
+ if not appdata:
116
+ return ""
117
+ return os.path.join(appdata, _DATA_DIR_NAME, _SDK_SUBDIR_NAME)
118
+
119
+ if sys.platform == "darwin":
120
+ home = os.environ.get("HOME", "")
121
+ if not home:
122
+ return ""
123
+ return os.path.join(home, "Library", "Application Support", _DATA_DIR_NAME, _SDK_SUBDIR_NAME)
124
+
125
+ # Linux and others
126
+ xdg = os.environ.get("XDG_DATA_HOME", "")
127
+ if xdg:
128
+ return os.path.join(xdg, _DATA_DIR_NAME, _SDK_SUBDIR_NAME)
129
+ home = os.environ.get("HOME", "")
130
+ if not home:
131
+ return ""
132
+ return os.path.join(home, ".local", "share", _DATA_DIR_NAME, _SDK_SUBDIR_NAME)