Skip to main content

The official Python library for the Ouro API

Project description

ouro-py

Version

The Ouro Python library provides convenient access to the Ouro REST API from any Python 3.7+ application. Visit Ouro to learn more about the Ouro platform.

Documentation

The REST API documentation can be found on ouro.foundation/docs.

Installation

# install from PyPI
pip install ouro-py

Usage

Generate an API key from your account settings by going to ouro.foundation/app/settings/api-keys.

Set your Ouro environment variables in a dotenv file, or using the shell:

export USER_API_KEY="your_ouro_api_key"

Init client:

import os
from ouro import Ouro

api_key = os.environ.get("USER_API_KEY")
ouro = Ouro(api_key=api_key)

Use the client to interface with the Ouro framework.

Create a dataset

data = pd.DataFrame(
    [
        {"name": "Bob", "age": 30},
        {"name": "Alice", "age": 27},
        {"name": "Matt", "age": 26},
    ]
)

res = ouro.elements.earth.datasets.create(
    data=data,
    name="your-dataset-name",
    description="your-dataset-description",
    visibility="private",
)

Read a dataset

id = "3d82308b-0747-45e4-8045-c8f7d2f6c0a6" # penguins dataset

# Retrieve a dataset
dataset = ouro.elements.earth.datasets.retrieve(id)

# Option 1: Load dataset's data as json using the table name
data = ouro.elements.earth.datasets.load("penguins")

# Option 2: Load dataset's data using tbe Postgrest client
data = ouro.database.table("penguins").select("*").limit(1).execute()

# Option 3: Read dataset's data as a Pandas DataFrame
df = ouro.elements.earth.datasets.query(id)

Update a dataset

id = "3d82308b-0747-45e4-8045-c8f7d2f6c0a6"
data_update = pd.DataFrame([
    {"name": "Bob", "age": 30},
    {"name": "Alice", "age": 27},
    {"name": "Matt", "age": 26},
])

update = {
    "visibility": "private",
    "data": data_update,
}
data = ouro.elements.earth.datasets.update("018f86da-b1be-7099-9556-fe88fb6882c3", **update)

Create a post

content = ouro.elements.air.Editor()
content.new_header(level=1, text="Hello World")
content.new_paragraph(text="This is a paragraph written in code.")

post = ouro.elements.air.posts.create(
    content=content,
    name="Hello World",
    description="This is a post from the Python SDK",
    visibility="private",
)

Read a post

id = "b9ff1bfd-b3ae-4e92-9afc-70b1e1e2011a" # The post id

post = ouro.elements.air.posts.retrieve(id)

Update a post

id = "b9ff1bfd-b3ae-4e92-9afc-70b1e1e2011a" # The post id

new_content = ouro.elements.air.Editor()
new_content.new_header(level=1, text="Hello World")
new_content.new_paragraph(text="This is a paragraph, but different this time.")

update = {
    "visibility": "public",
    "content": new_content,
}
post = ouro.elements.air.posts.update(id, **update)

Contributing

Contributing to the Python library is a great way to get involved with the Ouro community. Reach out to us on our Github Discussions page if you want to get involved.

Set up a Local Development Environment

Clone the Repository

git clone git@github.com:ourofoundation/ouro-py.git
cd ouro-py

Create and Activate a Virtual Environment

We recommend activating your virtual environment. Click here for more about Python virtual environments and working with conda and poetry.

Using venv (Python 3 built-in):

python3 -m venv env
source env/bin/activate  # On Windows, use .\env\Scripts\activate

Using conda:

conda create --name ouro-py
conda activate ouro-py

PyPi installation

Install the package (for > Python 3.7):

# with pip
pip install ouro-py

Local installation

You can also install locally after cloning this repo. Install Development mode with pip install -e, which makes it so when you edit the source code the changes will be reflected in your python module.

Badges

License: MIT CI Python

Codecov Last commit GitHub commit activity Github Stars Github Forks Github Watchers GitHub contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ouro_py-0.0.9.tar.gz (18.0 kB view hashes)

Uploaded Source

Built Distribution

ouro_py-0.0.9-py3-none-any.whl (23.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page