Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 73 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,80 @@ on:
branches: [master]

jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install lint dependencies
run: |
python -m pip install --upgrade pip
pip install black ruff pre-commit

- name: Run linter
run: git diff --name-only HEAD~10 HEAD | xargs pre-commit run --files

test:
name: Run Tests & Collect Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install coverage coveralls
pip install -r requirements.txt

- name: Run tests with coverage
run: coverage run -m unittest tests/load_tests.py -v

- name: Upload coverage data to coveralls.io
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ubuntu-latest - 3.12
COVERALLS_PARALLEL: true

coveralls:
name: Indicate completion to coveralls.io
needs: test
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install coveralls
run: pip install coveralls

- name: Finalize coveralls report
run: coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
name: Release
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -28,17 +99,8 @@ jobs:
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black ruff pre-commit
pip install -r requirements.txt

- name: Run linter
run: git diff --name-only HEAD~10 HEAD | xargs pre-commit run --files

- name: Run tests
run: python -m unittest tests/load_tests.py -v
- name: Install packaging dependencies
run: python -m pip install --upgrade setuptools wheel twine

- name: Release
env:
Expand Down
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,71 @@
# casibase-python-sdk

[![build Status](https://github.com/casdoor/casdoor-python-sdk/actions/workflows/build.yml/badge.svg)](https://github.com/casdoor/casdoor-python-sdk/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/casdoor/casdoor-python-sdk/badge.svg)](https://coveralls.io/github/casdoor/casdoor-python-sdk)
[![Version](https://img.shields.io/pypi/v/casibase-python-sdk.svg)](https://pypi.org/project/casibase-python-sdk)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casibase-python-sdk.svg)](https://pypi.org/project/casibase-python-sdk)
[![Pyversions](https://img.shields.io/pypi/pyversions/casibase-python-sdk.svg)](https://pypi.org/project/casibase-python-sdk)
[![Download](https://static.pepy.tech/badge/casibase-python-sdk)](https://pypi.org/project/casibase-python-sdk/)
[![License](https://img.shields.io/pypi/l/casibase-python-sdk.svg)](https://pypi.org/project/casibase-python-sdk/)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/5rPsrAzK7S)
This is the Python SDK for Casibase, which allows you to easily call Casibase's API.

casibase-python-sdk is available on PyPI:

```console
pip install casibase-python-sdk
```

Casibase SDK is simple to use. We will show you the steps below.

## Step1. Init Config

Initialization requires 5 parameters, which are all str type:

| Name (in order) | Must | Description |
| ---------------- | ---- | --------------------------------------------------- |
| endpoint | Yes | Casdoor Server Url, such as `https://demo-admin.casibase.com` |
| client_id | Yes | Application.client_id |
| client_secret | Yes | Application.client_secret |
| org_name | Yes | Organization name |
| application_name | Yes | Application name |

```python
from casibase_python_sdk import CasibaseSDK

sdk = CasibaseSDK(
endpoint,
client_id,
client_secret,
organization_name,
application_name,
)

```

## Step2. Record Operations

Used for logging operations, blockchain events, etc.

- Create: `record = Record.new(...)`; `sdk.add_record(record)`
- Query: `record_obj = sdk.get_record("name")`
- Update: `record_obj.attr = "new_val"`; `sdk.update_record(record_obj)`
- Delete: `sdk.delete_record(record_obj)`

## Step3. Store Operations

Used for managing knowledge bases, model configurations, etc.

- Create: `store = Store.new(...)`; `sdk.add_store(store)`
- Query: `store_obj = sdk.get_store(owner="admin", name="name")`
- Update: `store_obj.attr = "new_val"`; `sdk.update_store(store_obj)`
- Delete: `sdk.delete_store(store_obj)`

## Step4. Task Operations

Used for managing tasks, jobs, etc.

- Create: `task = Task.new(...)`; `sdk.add_task(task)`
- Query: `task_obj = sdk.get_task(owner="admin", name="name")`
- Update: `task_obj.attr = "new_val"`; `sdk.update_task(task_obj)`
- Delete: `sdk.delete_task(task_obj)`