Skip to content

Commit

Permalink
Adding readme with instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
mzkrasner committed Sep 24, 2024
1 parent 557797a commit d15e47d
Show file tree
Hide file tree
Showing 51 changed files with 76 additions and 1,183 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ENV_ID=
AGENT_ONE_SEED=
AGENT_TWO_SEED=
AGENT_THREE_SEED=
TABLE_ID=kjzl6hvfrbw6cac35814w419t0jesyz5ibs94hxla1fqputf2aazb9do5sxji9f
CONTEXT_ID=
CERAMIC_ENDPOINT="https://ceramic-orbisdb-mainnet-direct.hirenodes.io/"
ORBIS_ENDPOINT="https://studio.useorbis.com/api/db/query/json"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ coverage.xml

# Environments
.env
myenv/
.venv
env/
venv/
Expand Down
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# OrbisDB Python Starter

This repository is a modified version of the Index Network [Ceramic-Python](https://github.com/indexnetwork/ceramic-python) library that includes examples and slight modifications to be compatible with OrbisDB.

## Overview

This demo repository is structured as a simple Flask server that exposes a class called `CeramicActions` found in [examples.py](examples.py). This example architecture emulates an AI agent environment, and therefore assigns three imaginary agents individual Ceramic private keys so they can author data to the network.

Additionally, for no reason in particlar, the demo uses a [pageview](definition.json) data model. This has already been deployed to Ceramic, and is therefore provided in the example .env file as the default table value.

Finally, this demo only displays the use of raw SQL queries for reading data. However, OrbisDB also exposes a GraphQL endpoint for read capabilities (that you can easily incorporate into your code, if preferred).

## Getting Started

1. Create a copy of the example env file:

```bash
cp .env.example .env
```

2. OrbisDB Setup

To make things simple, we will use the hosted [OrbisDB Studio](https://studio.useorbis.com/) and the shared node instance it provides for this demo, but keep in mind that you can set up your separate instance whenever you want (more details at [OrbisDB](https://useorbis.com/)).

First, sign in with your wallet.

Once signed in, the studio will default to the `Contexts` tab at the top. On the right-hand side, you will see the shared node endpoints (already provided for you in your env file), as well as your environment ID. Go ahead and assign that value to `ENV_ID` in your new `.env` file.

Next, set up a context. These help developers segment their data models and usage based on the applications they are meant for. Create a new context (call it whatever you like), and assign the resulting string to `CONTEXT_ID` in your `.env` file.

3. Create your virtual environment and install dependencies:

```bash
python3 -m venv myenv
source myenv/bin/activate
pip3 install -r requirements.txt
```

4. Create and assign private Ceramic seeds to each of the agents in your .env file:

```bash
python3 seeds.py
```

Copy the strings corresponding to each agent from your terminal log and assign to each agent.

5. Finally, start your server:

```bash
python3 server.py
```

Your server will now be running on `http://127.0.0.1:5000/`

## Reading and Creating Data

You can reference the pseudocode provided in the [server.py](server.py) file. For example, creating a document:

```bash
curl -X POST "http://127.0.0.1:5000/create_document?agent=agent_three" \
-H "Content-Type: application/json" \
-d '{"page": "/home", "address": "0x8071f6F971B438f7c0EA72C950430EE7655faBCe", "customer_user_id": 3}'
```
7 changes: 3 additions & 4 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
AGENT_TWO_SEED = os.getenv("AGENT_TWO_SEED")
AGENT_THREE_SEED = os.getenv("AGENT_THREE_SEED")
CERAMIC_ENDPOINT = os.getenv("CERAMIC_ENDPOINT")

orbis_url = "https://studio.useorbis.com/api/db/query/json"
ORBIS_ENDPOINT = os.getenv("ORBIS_ENDPOINT")

switcher = {
"agent_one": AGENT_ONE_SEED,
Expand Down Expand Up @@ -86,7 +85,7 @@ def get_all_documents(self):
headers = {
"Content-Type": "application/json"
}
response = requests.post(url=orbis_url, headers=headers, json=body)
response = requests.post(url=ORBIS_ENDPOINT, headers=headers, json=body)
pprint(response.json())
return response.json()

Expand All @@ -112,6 +111,6 @@ def get_with_filter(self, filter):
headers = {
"Content-Type": "application/json"
}
response = requests.post(url=orbis_url, headers=headers, json=body)
response = requests.post(url=ORBIS_ENDPOINT, headers=headers, json=body)
pprint(response.json())
return response.json()
247 changes: 0 additions & 247 deletions myenv/bin/Activate.ps1

This file was deleted.

Loading

0 comments on commit d15e47d

Please sign in to comment.