Skip to content

Commit 8505a15

Browse files
author
Matt Kafonek
authored
Major overhaul, discriminator pattern for models, client updates (#132)
* Moving clients into Origami * wip * WIP, pushing branch up in order to work on it across machines * move models into api folder * fix imports * add path into File url * make file path a pathlib.Path * move kernels models out of api, fix imports * move kernels file * fix import * warning on downloading presigned url error * revert logging * temporary hack to support Skaffold dev * add mimetype to File model * update file model * more minio hacks * more info on warnings * don't use event in logging extrasgit status * fix file susbcribe reply parsing * fix imports and tests * update ci * remove deleted files * bump to alpha rc * ci * flake8 * make linter happy * yaml lint * default kernel state * fix for file subscribe parsing * logging * add cells to bottom of notebook by default * new queue execution method * slight tweak in syntax * run all test * add RTUClient timeout on file subscribes * move logging around * debugging RTUClient not initializing right * more debug * revert debug logs * updated README * docs * rename queue_execution * fix tests * update docs from Kyles feedback
1 parent 1b7590b commit 8505a15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3553
-5304
lines changed

.bumpversion.cfg

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,40 @@ jobs:
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v3
20-
- name: Setup nox
21-
uses: daisylb/setup-nox@v2.1.0
2220
- name: Setup poetry
2321
uses: Gr1N/setup-poetry@v8
2422
with:
2523
poetry-version: 1.4.2
2624
- name: Install dependencies
27-
run: |
28-
poetry install --all-extras --with dev
29-
pip install nox-poetry
30-
- name: Run tests
31-
run: nox -s test-${{ matrix.python_version }}
32-
- name: Generate coverage XML
33-
run: nox -s generate_coverage_xml
34-
- name: Upload coverage to Codecov
35-
uses: codecov/codecov-action@v3
25+
run: poetry install --all-extras --with dev
26+
27+
# Tests in Origami 1.0 alpha rc are end-to-end, need a live Noteable app.
28+
# Commenting tests out until we have time to configure Github repo with service account
29+
# access token and other settings so it can interact with Noteable from CI tests
30+
31+
# - name: Run tests with pytest
32+
# run: pytest -v --cov=origami
33+
34+
# - name: Upload coverage to Codecov
35+
# uses: codecov/codecov-action@v3
3636

3737
lint:
3838
runs-on: ubuntu-20.04
3939
steps:
4040
- name: Checkout code
4141
uses: actions/checkout@v3
42-
- name: Setup nox
43-
uses: daisylb/setup-nox@v2.1.0
4442
- name: Setup poetry
4543
uses: Gr1N/setup-poetry@v8
4644
with:
4745
poetry-version: 1.4.2
4846
- name: Install dependencies
49-
run: |
50-
poetry install --all-extras --with dev
51-
pip install nox-poetry
52-
- name: Run lint
53-
run: nox -s lint
47+
run: pip install flake8 black isort
48+
49+
- name: Lint with flake8
50+
run: flake8 origami --count --show-source --statistics --benchmark
51+
52+
- name: Check with black
53+
run: black --check origami
54+
55+
- name: Check with isort
56+
run: isort --diff --check origami

CONTRIBUTING.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ The project strucute follows this pattern:
2929

3030
```
3131
pyproject.toml # The repository toml for setup instructions
32-
mkdocs.yml # The configuration file
32+
mkdocs.yml # Docs configuration file
3333
docs/
3434
index.md # The documentation homepage.
3535
... # Other markdown pages, images and other files
36+
tests/
37+
... # End-to-end tests against a Noteable cluster
3638
origami/
37-
defs/ # Definitions for various pydantic types used
38-
tests/ # Unittests for the library
39-
client.py # The primary client module
40-
format.py # Notebook formatting helpers
41-
pathing.py # Pathing utilities
42-
```
39+
clients/
40+
api.py # HTTP API Client for CRUD resources
41+
rtu.py # RTU Client for live Notebook document model updates and cell execution
42+
cache.py # RTU Client cache for interacting with multiple Notebooks
43+
models/
44+
rtu/ # Real-time-update websocket payload models
45+
deltas/ # Document model updates within RTU Delta payloads
46+
notebook/
47+
... # In-memory Notebook builder that squashes RTU/Deltas
48+
```

README.md

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ Python 3.8+
4343

4444
## Installation
4545

46-
### Poetry
46+
For stable release:
47+
```bash
48+
pip install noteable-origami
49+
```
4750

48-
```shell
51+
```bash
4952
poetry add noteable-origami
5053
```
5154

52-
### Pip
53-
54-
```shell
55-
pip install noteable-origami
55+
For alpha pre-release:
56+
```bash
57+
pip install noteable-origami --pre
5658
```
5759

5860
<!-- --8<-- [end:install] -->
@@ -61,56 +63,73 @@ pip install noteable-origami
6163

6264
## Getting Started
6365

64-
Get your API token from Noteable within user settings.
65-
Within user settings, go to the API Token page, and generate a new token.
66+
> **Warning**
67+
Developer note: this documentation is written for the 1.0 alpha release. For stable release, see [pre-1.0 README](https://github.com/noteable-io/origami/blob/release/0.0.35/README.md)
6668

67-
```python
68-
from origami.client import NoteableClient
6969

70-
token = '' # Your API token from Noteable
70+
### API Tokens
7171

72-
# Establish a connection to the realtime API
73-
async with NoteableClient(api_token=token) as client:
74-
await client.ping_rtu()
75-
```
72+
The Noteable API requires an authentication token. You can manage tokens at the Noteable user settings page.
7673

77-
### Token via Environment Variable
74+
1. Log in to Noteable (sign up is free)
75+
2. In the User Settings tab, navigate to `API Tokens` and generate a new token
7876

79-
Alternatively you can set the environment variable:
77+
### Usage
8078

81-
```bash
82-
NOTEABLE_TOKEN=xxxx
83-
```
84-
85-
and skip assigning the token:
79+
The example below shows how to create a Notebook, launch a Kernel, add new cells, and execute code.
8680

8781
```python
88-
async with NoteableClient() as client:
89-
await client.ping_rtu()
90-
```
82+
# Grab a project_id from the Noteable UI, the url will look like: app.noteable.io/p/....
83+
api_token = '...'
9184

92-
### Custom Domain
85+
# Client for interacting with Noteables REST API
86+
from origami.clients.api import APIClient
87+
api_client = APIClient(api_token)
9388

94-
```bash
95-
NOTEABLE_TOKEN=xxxx
96-
NOTEABLE_DOMAIN=app.noteable.io
97-
```
89+
# Sanity check your user information
90+
user = await api_client.user_info()
9891

99-
And the client will use that particular domain, for custom deployment location. This value defaults to `app.noteable.io`.
92+
# Choose a project to create the notebook in, here using the ChatGPT plugin default project
93+
project_id = user.origamist_default_project_id
10094

101-
```python
102-
async with NoteableClient() as client:
103-
await client.ping_rtu()
95+
# Create a new Notebook
96+
file = await api_client.create_notebook(project_id=project_id, path="Demo.ipynb")
97+
98+
# Start a Kernel
99+
await api_client.launch_kernel(file.id)
100+
101+
# Client for Real-time Updates (RTU), used with Notebooks
102+
rtu_client = await api_client.rtu_client(file.id)
103+
104+
# Add a new cell
105+
from origami.models.notebook import CodeCell
106+
cell = CodeCell(source="print('Hello World')")
107+
await rtu_client.add_cell(cell)
108+
109+
# Execute the cell
110+
queued_execution = await rtu_client.queue_execution(cell.id)
111+
112+
# Wait for the execution to be complete, cell is an updated instance of CodeCell with metadata/outputs
113+
cell = await queued_execution
114+
115+
# Grab the output
116+
output_collection = await api_client.get_output_collection(cell.output_collection_id)
117+
print(output_collection.outputs[0].content.raw) # 'Hello World\n'
104118
```
105119

120+
106121
<!-- --8<-- [end:start] -->
107122

123+
124+
## 1.0 Roadmap
125+
126+
Origami is heading towards a 1.0 release. The alpha release candidate is on Pypi now, installable with a `--pre` flag. The 1.0 release represents a major refactor of the Origami using the best practices and lessons learned from creating multiple production API and RTU clients, including our ChatGPT plugin. It will likely come out of alpha once all of our internal applications are using the Origami 1.0 syntax.
127+
108128
## Contributing
109129

110130
See [CONTRIBUTING.md](./CONTRIBUTING.md).
111131

112132
---
113-
114133
<p align="center">Open sourced with ❤️ by <a href="https://noteable.io">Noteable</a> for the community.</p>
115134

116-
<img href="https://pages.noteable.io/private-beta-access" src="https://assets.noteable.io/github/2022-07-29/noteable.png" alt="Boost Data Collaboration with Notebooks">
135+
<img href="https://pages.noteable.io/private-beta-access" src="https://assets.noteable.io/github/2022-07-29/noteable.png" alt="Boost Data Collaboration with Notebooks">

RELEASING.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

noxfile.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

origami/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from importlib_metadata import version
2+
3+
__version__ = version("noteable-origami")

origami/_version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)