Skip to content

Commit

Permalink
python sdk docs with type hints + dataclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
sachaarbonel committed Sep 26, 2023
1 parent 887041f commit 4f7e162
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 23 deletions.
28 changes: 23 additions & 5 deletions docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ client.createToken(userId, exp, iat);
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
import time

# user ID
user_id = 'john'

# exp and iat are optional
# the token will be valid for 1 hour
exp = int(time.time()) + 60 * 60
iat = int(time.time())

client.create_token(user_id = user_id, exp = exp, iat = iat)
```

</TabItem>
Expand Down Expand Up @@ -80,15 +89,24 @@ const iat = Math.round(new Date().getTime() / 1000);

const call_cids = ['default:call1', 'livestream:call2'];

client.createToken(userId, exp, iat, call_cids);
client.createToken(user_id=user_id, exp=exp, iat=iat, call_cids=call_cids);
```

</TabItem>
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
import time

user_id = 'john'

# exp and iat are optional, token will be valid for 1 hour
exp = int(time.time()) + 60 * 60
iat = int(time.time())

call_cids = ['default:call1', 'livestream:call2']

client.create_token(user_id=user_id, exp, iat, call_cids)
```

</TabItem>
Expand Down
110 changes: 104 additions & 6 deletions docusaurus/video/docusaurus/docs/api/basics/calls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,27 @@ call.create({
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
# create a call
call.get_or_create_call(GetOrCreateCallRequest(
data=CallRequest(
created_by_id='john'
)
))
# create a call with more data
call.get_or_create_call(GetOrCreateCallRequest(
data=CallRequest(
created_by_id='john',
members=[
MemberRequest(
user_id: 'john',
role: 'admin'
),
MemberRequest(
user_id: 'jack'
)
]
),
))
```

</TabItem>
Expand Down Expand Up @@ -108,8 +127,19 @@ call.update({ custom: { color: 'red' } });
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
# update call settings
call.update_call(UpdateCallRequest(
settings_override=CallSettingsRequest(
audio=AudioSettingsRequest(
mic_default_on=True,
),
),
))

# update call with custom data
call.update_call(UpdateCallRequest(
custom={'color': 'red'}
))
```

</TabItem>
Expand Down Expand Up @@ -201,8 +231,22 @@ call.updateCallMembers({
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
# update or add call members

call.update_call(UpdateCallRequest(
members=[
MemberRequest(user_id: 'sara'),
MemberRequest(user_id: 'jack', role: 'admin')
]
))

# remove call members
# Assuming the updated call members are 'sara' and 'jack'
call.update_call(UpdateCallRequest(
members=[
MemberRequest(user_id: 'jack', role: 'admin')
]
))
```

</TabItem>
Expand Down Expand Up @@ -294,6 +338,33 @@ client.queryCalls({
});
```

</TabItem>

<TabItem value="py" label="Python">

```py
# default sorting
call.query_calls(data=QueryCallsRequest())

# sorting and pagination
response = call.query_calls(QueryCallsRequest(
sort= [SortParamRequest(field: 'starts_at', direction: -1)],
limit=2,
))

# loading next page
call.query_calls(QueryCallsRequest(
sort= [SortParamRequest(field: 'starts_at', direction: -1)],
limit=2,
next=response.data().next
))

# filtering
call.query_calls(QueryCallsRequest(
filter_conditions={'backstage': {'$eq': False}}
))
```

</TabItem>
</Tabs>

Expand Down Expand Up @@ -325,5 +396,32 @@ call.queryMembers({
});
```

</TabItem>

<TabItem value="py" label="Python">

```py
# default sorting
call.query_members(QueryMembersRequest())

# sorting and pagination
response = call.query_members(QueryMembersRequest(
sort: [SortParamRequest(field: "user_id", direction: 1)],
limit: 2,
))

# loading next page
call.query_members(QueryMembersRequest(
sort: [SortParamRequest(field: "user_id", direction: 1)],
limit: 2,
next: response.next,
))

# filtering
call.query_members(QueryMembersRequest(
filter_conditions: {"role": {"$eq": "admin"}},
))
```

</TabItem>
</Tabs>
42 changes: 32 additions & 10 deletions docusaurus/video/docusaurus/docs/api/basics/get_started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ call.create({
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
from getstream.models.get_or_create_call_request import GetOrCreateCallRequest
from getstream.models.call_request import CallRequest

call = client.video.call("default", "id")
response = call.get_or_create_call(GetOrCreateCallRequest(
data=CallRequest(
created_by_id="sacha",
),
))
```

</TabItem>
Expand Down Expand Up @@ -224,8 +231,9 @@ call.updateCallMembers({
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
call.update_call_members(UpdateCallMembersRequest(update_members=[
MemberRequest(user_id: "sara"),
MemberRequest(user_id: "emily", role: "admin")]))
```

</TabItem>
Expand Down Expand Up @@ -305,8 +313,19 @@ call.update({ custom: { color: 'red' } });
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
call.update(
UpdateCallRequest(
settings_override=CallSettingsRequest(
audio=AudioSettingsRequest(
mic_default_on=True,
default_device="speaker",
),
),
),
)

// or to update custom data
call.update(UpdateCallRequest( custom: { 'color': 'red' } ));
```

</TabItem>
Expand Down Expand Up @@ -473,8 +492,12 @@ const address = resp.call.ingress.rtmp.address.replace(
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
response = call.create(GetOrCreateCallRequest(
data=CallRequest(
created_by_id="sacha",
),
),)
rtmp_url = response.data().call.ingress.rtmp.address
```

</TabItem>
Expand Down Expand Up @@ -580,8 +603,7 @@ call.queryRecordings('<session ID>');
<TabItem value="py" label="Python">

```py
def hello_world():
print("Hello, world!")
recordings = call.list_recordings(session="your_session_id")
```

</TabItem>
Expand Down
Loading

0 comments on commit 4f7e162

Please sign in to comment.