Skip to content

Commit 49bf017

Browse files
authored
docs: updates readme with additional usage information (#131)
1 parent dff4038 commit 49bf017

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,36 @@ pip install posit-sdk
1212

1313
## Usage
1414

15+
Establish server information and credentials using the following environment variables or when initializing a client. Then checkout some [examples](./examples/0001-overview.qmd) to get started.
16+
17+
> [!CAUTION]
18+
> It is important to keep your API key safe and secure. Your API key grants access to your account and allows you to make authenticated requests to the Posit API. Treat your API key like a password and avoid sharing it with others. If you suspect that your API key has been compromised, regenerate a new one immediately to maintain the security of your account.
19+
20+
### Option 1 (Preferred)
21+
22+
```shell
23+
export CONNECT_API_KEY="my-secret-api-key"
24+
export CONNECT_SERVER="https://example.com/"
25+
```
26+
27+
```python
28+
from posit.connect import Client
29+
30+
with Client() as client:
31+
print(client)
32+
```
33+
34+
### Option 2
35+
1536
```python
1637
from posit.connect import Client
1738

18-
# If CONNECT_API_KEY and CONNECT_SERVER are set in your environment,
19-
# they will be picked up, or you can pass them as arguments
20-
con = Client()
21-
con.users.find()
39+
with Client(api_key="my-secret-api-key", url="https://example.com") as client:
40+
print(client)
2241
```
2342

43+
44+
2445
## Contributing
2546

2647
We welcome contributions to the Posit SDK for Python! If you would like to contribute, see the [CONTRIBUTING](CONTRIBUTING.md) guide for instructions.

examples/0001-overview.qmd

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Overview
2+
3+
This file provides a collection of short examples to help users get started.
4+
5+
The examples cover various aspects, including authentication, data retrieval, and data manipulation.
6+
7+
## Example - Print information for each user where `user_role='publisher'`
8+
9+
```python
10+
from posit.connect import Client
11+
12+
with Client() as client:
13+
for user in client.users.find(user_role='publisher'):
14+
print(user)
15+
```
16+
17+
## Example - Print information for a single user where `prefix='b'`
18+
19+
```python
20+
from posit.connect import Client
21+
22+
with Client() as client:
23+
user = client.users.find_one(prefix='b')
24+
print(user)
25+
```
26+
27+
## Example - Print the title for each content item that I own.
28+
29+
```python
30+
from posit.connect import Client
31+
32+
with Client() as client:
33+
guid = client.me.guid
34+
for item in client.content.find(owner_guid=guid)
35+
print(item.title)
36+
```
37+
38+
## Example - Update the title for a content item.
39+
40+
```python
41+
from posit.connect import Client
42+
43+
with Client() as client:
44+
guid = ... # the guid for a content item
45+
item = client.content.get(guid)
46+
item.update(title='New Title')
47+
```

0 commit comments

Comments
 (0)