-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path__init__.py
More file actions
148 lines (105 loc) · 3.51 KB
/
__init__.py
File metadata and controls
148 lines (105 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""Sift Client Library - Python client for interacting with Sift APIs.
!!! warning
The Sift Client is experimental and is subject to change.
## Overview
This library provides a high-level Python client for interacting with Sift APIs. It offers:
- **Synchronous and asynchronous interfaces** for all operations
- **Strong type checking** with Pydantic models
- **Pythonic API design** with intuitive method names
- **Comprehensive filtering** capabilities for queries
- **Automatic type conversion** between protobuf and Python types
## Installation
```bash
pip install sift-stack-py
```
## Quick Start
### Initialize the Client
```python
from sift_client import SiftClient
# Initialize with credentials
client = SiftClient(
api_key="your-api-key",
grpc_url="https://grpc-api.siftstack.com",
rest_url="https://api.siftstack.com"
)
```
### Basic Operations
```python
# Get an asset
asset = client.assets.get(asset_id="asset123")
# List resources with filtering
runs = client.runs.list_(
assets=[asset.id_],
start_time_after=datetime.now() - timedelta(days=7),
limit=10
)
# Update a resource
asset.update({"tags": ["production", "v2"]})
# Create a new resource
run = client.runs.create({
"name": "Test Run",
"asset_ids": [asset.id_],
"start_time": datetime.now()
})
```
### Async Usage
```python
import asyncio
async def main():
# Use async_ accessor for async operations
asset = await client.async_.assets.get(asset_id="asset123")
runs = await client.async_.runs.list_(limit=10)
return asset, runs
result = asyncio.run(main())
```
## Key Components
### Resources
Resource APIs provide methods for interacting with Sift services. Each resource supports
operations like `get()`, `list_()`, `create()`, `update()`, and `archive()`.
**Available Resources:**
- `client.assets` - Manage physical or logical entities
- `client.runs` - Manage time-bounded operational periods
- etc.
See [resources](resources/) for detailed documentation and a complete list.
### Types
Sift types are immutable Pydantic models representing Sift objects. They provide
type-safe access to properties and convenience methods for common operations.
**Available Types:**
- `Asset`, `AssetUpdate` - Asset resources
- `Run`, `RunCreate`, `RunUpdate` - Run resources
- etc.
See [sift_types](sift_types/) for detailed documentation and a complete list.
## Examples
For complete examples, see the [examples](../examples/) directory.
## Connection Configuration
For advanced connection options:
```python
from sift_client.transport import SiftConnectionConfig, GrpcConfig, RestConfig
config = SiftConnectionConfig(
grpc_config=GrpcConfig(
uri="https://grpc-api.siftstack.com",
api_key="your-api-key",
use_ssl=True
),
rest_config=RestConfig(
uri="https://api.siftstack.com",
api_key="your-api-key"
)
)
client = SiftClient(connection_config=config)
```
## Best Practices
1. **Use sync APIs** for notebooks, scripts, and simple applications
2. **Use async APIs** for high-performance services with concurrent operations
3. **Leverage filtering** to reduce data transfer and improve performance
4. **Reuse client instances** rather than creating new ones for each operation
5. **Use type hints** to get full IDE support and catch errors early
"""
import logging
from sift_client.client import SiftClient
from sift_client.transport import SiftConnectionConfig
__all__ = [
"SiftClient",
"SiftConnectionConfig",
]
logging.getLogger(__name__).addHandler(logging.NullHandler())