Skip to content

Commit f8d94db

Browse files
Merge pull request #63 from nitrictech/develop
Release
2 parents f3c084c + b3e5875 commit f8d94db

40 files changed

Lines changed: 2075 additions & 88 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,5 @@ dmypy.json
143143
# Cython debug symbols
144144
cython_debug/
145145

146+
147+
.vscode/

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ repos:
88
rev: 3.7.9
99
hooks:
1010
- id: flake8
11-
exclude: ^(venv|tests|build|dist|nitric/proto|examples)/
11+
exclude: ^(venv|tests|build|dist|nitric/proto|examples)/
12+
- repo: https://github.com/pycqa/pydocstyle
13+
rev: 6.0.0
14+
hooks:
15+
- id: pydocstyle
16+
args:
17+
- --ignore=D100, D105, D203, D212, D415
18+
exclude: ^(venv|tests|build|dist|nitric/proto|examples)/

README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,36 @@
88

99
# Nitric Python SDK
1010

11-
The Python SDK supports the use of the cloud-portable [Nitric](https://nitric.io) framework with Python 3.7+.
11+
The Python SDK supports the use of the cloud-portable [Nitric](https://nitric.io) framework with Python 3.
1212

1313
> The Nitric Python SDK is currently in Preview, API changes are likely prior to v1.x release.
1414
1515
Read full documentation [here](https://nitrictech.github.io/python-sdk/).
1616

17-
## Usage
17+
## Prerequisites
18+
19+
- Python 3.8+
20+
21+
## Getting Started
1822

19-
### Nitric Functions (FaaS):
23+
### Using the [Nitric CLI](https://github.com/nitrictech/cli)
2024

21-
- Install Python 3.7+
22-
- Install the [Nitric CLI](https://nitric.io/docs/installation?lang=python)
23-
- Create / Open a Nitric Project
24-
- Make a Python37 function
25-
26-
```bash
27-
# Create a new project
28-
nitric make:project example-python
29-
cd example-python
25+
> nitric is included in all python related projects by default
3026
31-
# Create a python37 Nitric Function
32-
nitric make:service function/python37 example-function
27+
```bash
28+
nitric stack new
3329
```
3430

35-
> note: The SDK will be included in the requirements.txt of a new Python function by default.
31+
Then select `official/Python Stack`
3632

37-
### Standard Python Project
33+
### Adding to an existing project
3834

39-
- Install Python 3.7+
35+
**pip**
4036

4137
```bash
4238
# Install the Nitric SDK
4339
pip3 install nitric
4440
```
4541

46-
```python
47-
# import classes/modules as required
48-
from nitric.api import Events, KeyValueClient
49-
```
42+
## Usage
43+
[Nitric Documentation](https://nitric.io/docs)

examples/events/event_ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async def events_event_ids():
1010
payload = {"content": "of event"}
1111

1212
# Publish an event to the topic 'my-topic'
13-
event = await topic.publish(Event(payload=payload))
13+
event = await topic.publish(Event(id="unique-event-id", payload=payload))
1414

1515

1616
# [END snippet]

examples/queues/failed.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
from typing import List
33
from nitric.api import Queues, Task
44
from nitric.api.queues import FailedTask
5+
56
# [END import]
67
async def queues_failed():
7-
# [START snippet]
8-
# Construct a new queue client with default settings
8+
# [START snippet]
9+
# Construct a new queue client with default settings
910
queues = Queues()
1011

1112
payload = {"content": "of task"}
1213

1314
# Publish tasks to queue
1415
failed_task = await queues.queue("my-queue").send([Task(payload=payload) for i in range(2)])
15-
16+
1617
# Process the failed task
1718
for task in failed_task:
18-
print(task.message)
19-
# [END snippet]
19+
print(task.message)
20+
21+
22+
# [END snippet]

examples/queues/send_id.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [START import]
2+
from nitric.api import Queues, Task
3+
4+
# [END import]
5+
async def queues_send():
6+
# [START snippet]
7+
# Construct a new queue client with default settings
8+
queues = Queues()
9+
10+
payload = {"content": "of task"}
11+
12+
# Publish a task to a queue
13+
await queues.queue("my-queue").send(Task(id="unique-task-id", payload=payload))
14+
15+
16+
# [END snippet]

examples/storage/sign_url_read.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [START import]
2+
from nitric.api import Storage
3+
from nitric.api.storage import FileMode
4+
5+
# [END import]
6+
async def storage_sign_url_read():
7+
# [START snippet]
8+
# Construct a new storage client with default settings
9+
storage = Storage()
10+
11+
# Create a readonly presigned url for the file valid for the next 3600 seconds
12+
await storage.bucket("my-bucket").file("path/to/item").sign_url(mode=FileMode.READ, expiry=3600)
13+
14+
15+
# [END snippet]

examples/storage/sign_url_write.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [START import]
2+
from nitric.api import Storage
3+
from nitric.api.storage import FileMode
4+
5+
# [END import]
6+
async def storage_sign_url_write():
7+
# [START snippet]
8+
# Construct a new storage client with default settings
9+
storage = Storage()
10+
11+
# Create a writable presigned url for the file valid for the next 3600 seconds
12+
await storage.bucket("my-bucket").file("path/to/item").sign_url(mode=FileMode.WRITE, expiry=3600)
13+
14+
15+
# [END snippet]

nitric/api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# limitations under the License.
1818
#
1919
"""Nitric API SDK."""
20-
from nitric.api.events import Events, Event, Topic
20+
from nitric.api.events import Events, Event, TopicRef
2121
from nitric.api.queues import Queues, Task, FailedTask
2222
from nitric.api.storage import Storage
2323
from nitric.api.documents import Documents
@@ -31,6 +31,6 @@
3131
"Event",
3232
"Task",
3333
"FailedTask",
34-
"Topic",
34+
"TopicRef",
3535
"Secrets",
3636
]

nitric/api/events.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _event_to_wire(event: Event) -> NitricEvent:
4646

4747

4848
@dataclass(frozen=True, order=True)
49-
class Topic(object):
49+
class TopicRef(object):
5050
"""A reference to a topic on an event service, used to perform operations on that topic."""
5151

5252
_events: Events
@@ -94,14 +94,14 @@ def __del__(self):
9494
if self.channel is not None:
9595
self.channel.close()
9696

97-
async def topics(self) -> List[Topic]:
97+
async def topics(self) -> List[TopicRef]:
9898
"""Get a list of topics available for publishing or subscription."""
9999
try:
100100
response = await self._topic_stub.list()
101101
return [self.topic(topic.name) for topic in response.topics]
102102
except GRPCError as grpc_err:
103103
raise exception_from_grpc_error(grpc_err)
104104

105-
def topic(self, name: str) -> Topic:
105+
def topic(self, name: str) -> TopicRef:
106106
"""Return a reference to a topic."""
107-
return Topic(_events=self, name=name)
107+
return TopicRef(_events=self, name=name)

0 commit comments

Comments
 (0)