0
# Client Management
1
2
Core client functionality for connecting to tus servers, managing authentication headers, and creating uploader instances. The TusClient class serves as the entry point for all tus protocol operations.
3
4
## Capabilities
5
6
### TusClient Class
7
8
The main client class for interacting with tus resumable upload servers.
9
10
```python { .api }
11
class TusClient:
12
"""
13
Object representation of Tus client.
14
15
Attributes:
16
url (str): The tus server's create extension URL
17
headers (dict): Server-specific headers sent with every request
18
client_cert (str | tuple[str, str]): Path to PEM encoded client certificate
19
"""
20
21
def __init__(self, url: str, headers: Optional[Dict[str, str]] = None,
22
client_cert: Optional[Union[str, Tuple[str, str]]] = None):
23
"""
24
Initialize TusClient.
25
26
Parameters:
27
- url (str): The tus server's create extension URL
28
- headers (Optional[Dict[str, str]]): Custom headers for authentication
29
- client_cert (Optional[Union[str, Tuple[str, str]]]): Client certificate path(s)
30
"""
31
```
32
33
### Header Management
34
35
Update client headers for authentication and custom server requirements.
36
37
```python { .api }
38
def set_headers(self, headers: Dict[str, str]):
39
"""
40
Set tus client headers.
41
42
Update and/or set new headers that would be sent along with every request
43
made to the server.
44
45
Parameters:
46
- headers (dict): Key-value pairs of headers to be set
47
"""
48
```
49
50
### Uploader Creation
51
52
Factory methods for creating uploader instances.
53
54
```python { .api }
55
def uploader(self, *args, **kwargs) -> Uploader:
56
"""
57
Return synchronous uploader instance pointing at current client.
58
59
Return uploader instance with which you can control the upload of a specific
60
file. The current instance of the tus client is passed to the uploader on creation.
61
62
Parameters:
63
See tusclient.uploader.Uploader for required and optional arguments.
64
65
Returns:
66
Uploader: Configured uploader instance
67
"""
68
69
def async_uploader(self, *args, **kwargs) -> AsyncUploader:
70
"""
71
Return asynchronous uploader instance pointing at current client.
72
73
Parameters:
74
See tusclient.uploader.AsyncUploader for required and optional arguments.
75
76
Returns:
77
AsyncUploader: Configured async uploader instance
78
"""
79
```
80
81
## Usage Examples
82
83
### Basic Client Setup
84
85
```python
86
from tusclient import client
87
88
# Simple client
89
my_client = client.TusClient('http://tusd.tusdemo.net/files/')
90
91
# Client with authentication headers
92
my_client = client.TusClient(
93
'http://tusd.tusdemo.net/files/',
94
headers={'Authorization': 'Bearer your-token-here'}
95
)
96
97
# Client with client certificate
98
my_client = client.TusClient(
99
'https://secure-tus-server.com/files/',
100
client_cert='/path/to/client.pem'
101
)
102
103
# Client with certificate and separate key file
104
my_client = client.TusClient(
105
'https://secure-tus-server.com/files/',
106
client_cert=('/path/to/client.crt', '/path/to/client.key')
107
)
108
```
109
110
### Header Management
111
112
```python
113
# Update headers after client creation
114
my_client.set_headers({'Authorization': 'Bearer new-token'})
115
116
# Add additional headers
117
my_client.set_headers({
118
'X-Custom-Header': 'custom-value',
119
'X-Upload-Metadata': 'filename dGVzdC5kYXQ='
120
})
121
```
122
123
### Creating Uploaders
124
125
```python
126
# Create synchronous uploader
127
uploader = my_client.uploader(
128
'/path/to/file.ext',
129
chunk_size=1024*1024,
130
metadata={'filename': 'test.dat'}
131
)
132
133
# Create asynchronous uploader
134
async_uploader = my_client.async_uploader(
135
'/path/to/file.ext',
136
chunk_size=1024*1024,
137
retries=3,
138
retry_delay=5
139
)
140
```