diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index e1e14aa0..784287dd 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -30,7 +30,7 @@ What would you expect to happen when following the steps above? We want to make sure the problem isn't specific to your operating system or programming language. - **Operating System/Version:** (ex. MacOS 14.2, Windows 10, RHEL 6, etc) -- **Go Version:** (ex. v1.18) +- **Python Version:** (ex. v1.18) --> diff --git a/.github/workflows/CD-dev.yml b/.github/workflows/CD-dev.yml index 31b249ec..e46cf80d 100644 --- a/.github/workflows/CD-dev.yml +++ b/.github/workflows/CD-dev.yml @@ -1,4 +1,4 @@ -name: Development Releases +name: CD - Publish Development Releases on: push: @@ -14,14 +14,14 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: - python-version: '3.10' - + python-version: '3.10' + - name: Update Version in __init__.py run: | sed -i 's/0.0.0/${{ github.ref_name }}/g' ./deepgram/__init__.py sed -i 's/name = "deepgram-sdk"/name = "deepgram-unstable-sdk"/g' ./pyproject.toml sed -i 's/name="deepgram-sdk"/name="deepgram-unstable-sdk"/g' ./setup.py - + - name: Install Dependencies run: pip install . @@ -40,4 +40,4 @@ jobs: - name: Publish to PyPi uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_DEV_API_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_DEV_API_TOKEN }} diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yaml similarity index 86% rename from .github/workflows/CD.yml rename to .github/workflows/CD.yaml index 87c1f719..9030eb0f 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yaml @@ -1,8 +1,9 @@ -name: CD +name: CD - Publish Releases on: release: types: [ published ] + jobs: build: runs-on: ubuntu-latest @@ -10,11 +11,11 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' - + python-version: '3.10' + - name: Update Version in __init__.py run: sed -i 's/0.0.0/${{ github.event.release.tag_name }}/g' ./deepgram/__init__.py - + - name: Install Dependencies run: pip install . @@ -33,4 +34,4 @@ jobs: - name: Publish to PyPi uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yaml similarity index 83% rename from .github/workflows/CI.yml rename to .github/workflows/CI.yaml index 9a739653..8ecbc5eb 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yaml @@ -1,10 +1,11 @@ -name: CI +name: CI - Build SDK on: push: branches: [ main ] pull_request: branches: [ main ] + jobs: build: runs-on: ubuntu-latest @@ -12,8 +13,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.10' - + python-version: '3.10' + - name: Install Dependencies run: pip install . @@ -24,4 +25,4 @@ jobs: run: python -m pip install --upgrade build - name: Build SDK - run: python -m build \ No newline at end of file + run: python -m build diff --git a/.github/workflows/PyDocs.yml b/.github/workflows/PyDocs.yaml similarity index 72% rename from .github/workflows/PyDocs.yml rename to .github/workflows/PyDocs.yaml index 028ecd43..8a0896b5 100644 --- a/.github/workflows/PyDocs.yml +++ b/.github/workflows/PyDocs.yaml @@ -3,22 +3,21 @@ name: Generate PyDocs on Release on: push: tags: - - "v[0-9]+.[0-9]+.[0-9]+" - - "v[0-9]+.[0-9]+.[0-9]+-doc.[0-9]+" - + - "v[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+.[0-9]+.[0-9]+-doc.[0-9]+" jobs: build-and-deploy: runs-on: ubuntu-latest - + steps: - - name: Checkout code from main branch + - name: Checkout code from main branch uses: actions/checkout@v3 with: ref: main repository: ${{ github.repository }} - - name: Set up Python + - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.11' @@ -30,13 +29,13 @@ jobs: pip install --upgrade py2app pip install python-dotenv pip install -r requirements.txt - + - name: Get the current tag name run: echo "TAG_NAME=${GITHUB_REF##*/}" >> "$GITHUB_ENV" # New Step: Extracting Major Version Number - name: Set the current major version - run: echo "MAJOR_VERSION=$(echo $TAG_NAME | cut -d '.' -f 1)" >> "$GITHUB_ENV" # This extracts the major version assuming a 'vX.Y.Z' format + run: echo "MAJOR_VERSION=$(echo "$TAG_NAME" | cut -d '.' -f 1)" >> "$GITHUB_ENV" # This extracts the major version assuming a 'vX.Y.Z' format - name: Checkout the gh-pages branch uses: actions/checkout@v3 @@ -46,12 +45,12 @@ jobs: - name: Generate Documentation for the current tag run: | - ROOT_PATH=$(pwd) # Moved this line up to ensure ROOT_PATH is set before its usage - rm -rf $ROOT_PATH/gh-pages/docs/$MAJOR_VERSION - mkdir -p $ROOT_PATH/gh-pages/docs/$MAJOR_VERSION # Note: Changed to use MAJOR_VERSION to create/update the major version folder - cd $ROOT_PATH/deepgram - pdoc $ROOT_PATH/deepgram -o $ROOT_PATH/gh-pages/docs/$MAJOR_VERSION # Documentation is generated/updated in the major version folder - + ROOT_PATH="$(pwd)" # Moved this line up to ensure ROOT_PATH is set before its usage + rm -rf "$ROOT_PATH/gh-pages/docs/$MAJOR_VERSION" + mkdir -p "$ROOT_PATH/gh-pages/docs/$MAJOR_VERSION" # Note: Changed to use MAJOR_VERSION to create/update the major version folder + cd "$ROOT_PATH/deepgram" + pdoc "$ROOT_PATH/deepgram" -o "$ROOT_PATH/gh-pages/docs/$MAJOR_VERSION" # Documentation is generated/updated in the major version folder + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: diff --git a/.github/workflows/check-actionlint.yaml b/.github/workflows/check-actionlint.yaml new file mode 100644 index 00000000..7e6404e4 --- /dev/null +++ b/.github/workflows/check-actionlint.yaml @@ -0,0 +1,31 @@ +name: Check - actionlint + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened + paths: + - ".github/workflows/**" + +jobs: + checkactionlint: + name: Check actionlint + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-python-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Run actionlint + run: | + make actionlint diff --git a/.github/workflows/check-all.yaml b/.github/workflows/check-all.yaml new file mode 100644 index 00000000..e996d019 --- /dev/null +++ b/.github/workflows/check-all.yaml @@ -0,0 +1,35 @@ +name: Check - All linters, etc +on: + push: + branches: + - main + - release-* + tags-ignore: + - "**" + +jobs: + build: + name: Change to Main/Release Branch + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-python-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: "1.19" + id: go + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Run all checks + shell: bash + run: | + make check diff --git a/.github/workflows/check-lint.yaml.DISABLE b/.github/workflows/check-lint.yaml.DISABLE new file mode 100644 index 00000000..f3da7692 --- /dev/null +++ b/.github/workflows/check-lint.yaml.DISABLE @@ -0,0 +1,53 @@ +name: Check - lint + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened + paths: + - "**.go" + - "**/go.mod" + - ".golangci.yaml" + +jobs: + checklint: + name: Lint + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-go-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: "1.19" + id: go + + # - name: Get Date + # id: get-date + # shell: bash + # run: | + # echo "date=$(date -u "+%Y-%m")" >> $GITHUB_OUTPUT + + - name: Restore Lint Cache + uses: actions/cache@v3 + timeout-minutes: 10 + continue-on-error: true + with: + path: ${{ runner.temp }}/lint_cache + # key: ${{ runner.os }}-lint-cache-${{ steps.get-date.outputs.date }} + key: ${{ runner.os }}-lint-cache + restore-keys: | + ${{ runner.os }}-lint-cache + + - name: Run golangci-lint + env: + GOLANGCI_LINT_CACHE: ${{ runner.temp }}/lint_cache + run: | + make lint diff --git a/.github/workflows/check-mdlint.yaml b/.github/workflows/check-mdlint.yaml new file mode 100644 index 00000000..0546ae6f --- /dev/null +++ b/.github/workflows/check-mdlint.yaml @@ -0,0 +1,32 @@ +name: Check - mdlint + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened + paths: + - "**.md" + - "hack/check/check-mdlint.sh" + +jobs: + checkmdlint: + name: Check mdlint + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-python-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Run mdlint + run: | + make mdlint diff --git a/.github/workflows/check-shell.yaml b/.github/workflows/check-shell.yaml new file mode 100644 index 00000000..09627f22 --- /dev/null +++ b/.github/workflows/check-shell.yaml @@ -0,0 +1,33 @@ +name: Check - shell + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened + paths: + - "**/Makefile" + - "**.sh" + - "hack/check/check-shell.sh" + +jobs: + checkshell: + name: Check shell + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-python-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Run shellcheck + run: | + make shellcheck diff --git a/.github/workflows/check-yaml.yaml b/.github/workflows/check-yaml.yaml new file mode 100644 index 00000000..bbee1bee --- /dev/null +++ b/.github/workflows/check-yaml.yaml @@ -0,0 +1,31 @@ +name: Check - yaml + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened + paths: + - ".github/workflows/**" + +jobs: + checkmdlint: + name: Check mdlint + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-python-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Run mdlint + run: | + make mdlint diff --git a/.github/workflows/tests-daily.yaml.DISABLE b/.github/workflows/tests-daily.yaml.DISABLE new file mode 100644 index 00000000..9793e36b --- /dev/null +++ b/.github/workflows/tests-daily.yaml.DISABLE @@ -0,0 +1,57 @@ +name: Build - Daily Official Build + +on: + workflow_dispatch: + repository_dispatch: + types: + - manual-daily-build + schedule: + - cron: "0 9 * * *" + +jobs: + build-release: + name: Daily Build Tests + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-go-sdk' + runs-on: ubuntu-latest + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Set up Go 1.x + uses: actions/setup-go@v3 + with: + go-version: "1.19" + id: go + + - name: Config git + env: + GITHUB_TOKEN: ${{ secrets.GH_RELEASE_ACCESS_TOKEN }} + shell: bash + run: | + git config --global init.defaultBranch main + git config --global pull.rebase true + git config --global url."https://git:$GITHUB_TOKEN@github.com".insteadOf "https://github.com" + + - name: Get dependencies + shell: bash + run: | + make ensure-deps + + - name: Get dependencies + shell: bash + run: | + BRANCH_NAME="response-shape-${{ github.run_id }}" + git checkout -b "$BRANCH_NAME" + + # run daily tests + go test -v -run TestDaily_ ./... + + # create a PR + git add -A ./tests/response_data + git commit -s -m "auto-generated - update Response Shapes" + git push origin "$BRANCH_NAME" + gh pr create --title "auto-generated - update API spec" --body "auto-generated - update API spec" --base "main" + sleep 30 + gh pr merge "$BRANCH_NAME" --delete-branch --squash --admin diff --git a/.github/workflows/tests-unit.yaml.DISABLE b/.github/workflows/tests-unit.yaml.DISABLE new file mode 100644 index 00000000..f63c7fd4 --- /dev/null +++ b/.github/workflows/tests-unit.yaml.DISABLE @@ -0,0 +1,47 @@ +name: Go Tests + +on: + pull_request: + types: + - assigned + - opened + - synchronize + - reopened +jobs: + build: + name: Go Tests + # Only run this job if we're in the main repo, not a fork. + if: github.repository == 'deepgram/deepgram-go-sdk' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + + - name: Checkout code by commit + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.19" + + - name: Ensure dependencies installed + shell: bash + run: | + make ensure-deps + + - name: Go Tidy + shell: bash + run: go mod tidy + + - name: Go Mod + shell: bash + run: go mod download + + - name: Go Mod Verify + shell: bash + run: go mod verify + + - name: Run Tests + shell: bash + run: | + go test -v -run Test_ ./... diff --git a/.markdownlintrc b/.markdownlintrc new file mode 100644 index 00000000..a7470110 --- /dev/null +++ b/.markdownlintrc @@ -0,0 +1,7 @@ +{ + "default": true, + "line_length": false, + "MD024": { "allow_different_nesting": true }, + "MD026": { "punctuation": ".,;:!" }, + "MD046": { "style": "fenced" } +} diff --git a/.yamllintconfig.yaml b/.yamllintconfig.yaml new file mode 100644 index 00000000..66487c03 --- /dev/null +++ b/.yamllintconfig.yaml @@ -0,0 +1,18 @@ +--- +extends: relaxed + +rules: + line-length: disable + trailing-spaces: enable + new-line-at-end-of-file: enable + new-lines: + type: unix + indentation: disable + key-duplicates: disable + empty-lines: enable + colons: disable + commas: disable + +ignore: | + /deepgram-python-sdk/.github/ISSUE_TEMPLATE/config.yml + /deepgram-python-sdk/addons/**/*/ diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..7b7b3c93 --- /dev/null +++ b/Makefile @@ -0,0 +1,78 @@ +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +# detect the build OS +ifeq ($(OS),Windows_NT) + build_OS := Windows + NUL = NUL +else + build_OS := $(shell uname -s 2>/dev/null || echo Unknown) + NUL = /dev/null +endif + +.DEFAULT_GOAL:=help + +##### GLOBAL +ROOT_DIR := $(shell git rev-parse --show-toplevel) + +# Add tooling binaries here and in hack/tools/Makefile +TOOLS_BIN_DIR := $(shell mktemp -d) + +help: #### Display help + @echo '' + @echo 'Syntax: make ' + @awk 'BEGIN {FS = ":.*## "; printf "\nTargets:\n"} /^[a-zA-Z_-]+:.*?#### / { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @echo '' +##### GLOBAL + +##### LINTING TARGETS +.PHONY: version +version: #### display version of components + @echo 'ROOT_DIR: $(ROOT_DIR)' + @echo 'GOOS: $(GOOS)' + @echo 'GOARCH: $(GOARCH)' + @echo 'go version: $(shell go version)' + +.PHONY: check mdlint shellcheck actionlint yamllint ### Performs all of the checks, lint'ing, etc available +check: mdlint shellcheck actionlint yamllint + +.PHONY: ensure-deps +ensure-deps: #### Ensure that all required dependency utilities are downloaded or installed + hack/ensure-deps/ensure-dependencies.sh + +GO_MODULES=$(shell find . -path "*/go.mod" | xargs -I _ dirname _) + +# lint: tools #### Performs Golang programming lint +# @for i in $(GO_MODULES); do \ +# echo "-- Linting $$i --"; \ +# working_dir=`pwd`; \ +# if [ "$${i}" = "." ]; then \ +# $(GOLANGCI_LINT) run -v --timeout=5m; \ +# else \ +# cd $${i}; \ +# $(MAKE) lint || exit 1; \ +# cd $$working_dir; \ +# fi; \ +# done; \ +# CHECK=$$(grep -r --include="*.go" ioutil ./); \ +# if [ -n "$${CHECK}" ]; then \ +# echo "ioutil is deprecated, use io or os replacements"; \ +# echo "$${CHECK}"; \ +# exit 1; \ +# fi + +mdlint: #### Performs Markdown lint + # mdlint rules with common errors and possible fixes can be found here: + # https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md + hack/check/check-mdlint.sh + +shellcheck: #### Performs bash/shell lint + hack/check/check-shell.sh + +yamllint: #### Performs yaml lint + hack/check/check-yaml.sh + +actionlint: #### Performs GitHub Actions lint + actionlint +##### LINTING TARGETS diff --git a/README.md b/README.md index 0e0f7728..0c3ec6c3 100644 --- a/README.md +++ b/README.md @@ -19,19 +19,19 @@ Official Python SDK for [Deepgram](https://www.deepgram.com/). Power your apps w - [Development and Contributing](#development-and-contributing) - [Getting Help](#getting-help) -# Documentation +## Documentation You can learn more about the Deepgram API at [developers.deepgram.com](https://developers.deepgram.com/docs). -# Getting an API Key +## Getting an API Key 🔑 To access the Deepgram API you will need a [free Deepgram API Key](https://console.deepgram.com/signup?jump=keys). -# Requirements +## Requirements [Python](https://www.python.org/downloads/) (version ^3.10) -# Installation +## Installation To install the latest version available (which will guarantee change over time): @@ -43,7 +43,7 @@ If you are going to write an application to consume this SDK, it's [highly recom In a `requirements.txt` file, pinning to a major (or minor) version, like if you want to stick to using the SDK `v2.12.0` release, that can be done like this: -``` +```sh deepgram-sdk==2.* ``` @@ -55,7 +55,7 @@ pip install deepgram-sdk==2.* Pinning to a specific version can be done like this in a `requirements.txt` file: -``` +```sh deepgram-sdk==2.12.0 ``` @@ -67,11 +67,11 @@ pip install deepgram-sdk==2.12.0 We guarantee that major interfaces will not break in a given major semver (ie `2.*` release). However, all bets are off moving from a `2.*` to `3.*` major release. This follows standard semver best-practices. -# Quickstarts +## Quickstarts This SDK aims to reduce complexity and abtract/hide some internal Deepgram details that clients shouldn't need to know about. However you can still tweak options and settings if you need. -## PreRecorded Audio Transcription Quickstart +### PreRecorded Audio Transcription Quickstart You can find a [walkthrough](https://developers.deepgram.com/docs/python-sdk-pre-recorded-transcription) on our documentation site. Transcribing Pre-Recorded Audio can be done using the following sample code: @@ -80,10 +80,10 @@ AUDIO_URL = { "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" } -# STEP 1 Create a Deepgram client using the API key from environment variables +## STEP 1 Create a Deepgram client using the API key from environment variables deepgram: DeepgramClient = DeepgramClient("", ClientOptionsFromEnv()) -# STEP 2 Call the transcribe_url method on the prerecorded class +## STEP 2 Call the transcribe_url method on the prerecorded class options: PrerecordedOptions = PrerecordedOptions( model="nova-2", smart_format=True, @@ -92,7 +92,7 @@ response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options) print(f"response: {response}\n\n") ``` -## Live Audio Transcription Quickstart +### Live Audio Transcription Quickstart You can find a [walkthrough](https://developers.deepgram.com/docs/live-streaming-audio-transcription) on our documentation site. Transcribing Live Audio can be done using the following sample code: @@ -140,73 +140,71 @@ options: LiveOptions = LiveOptions( encoding="linear16", channels=1, sample_rate=16000, - # To get UtteranceEnd, the following must be set: + ## To get UtteranceEnd, the following must be set: interim_results=True, utterance_end_ms="1000", vad_events=True, ) dg_connection.start(options) -# create microphone +## create microphone microphone = Microphone(dg_connection.send) -# start microphone +## start microphone microphone.start() -# wait until finished +## wait until finished input("Press Enter to stop recording...\n\n") -# Wait for the microphone to close +## Wait for the microphone to close microphone.finish() -# Indicate that we've finished +## Indicate that we've finished dg_connection.finish() print("Finished") ``` -# Examples +## Examples There are examples for **every** API call in this SDK. You can find all of these examples in the [examples folder](https://github.com/deepgram/deepgram-python-sdk/tree/main/examples) at the root of this repo. These examples provide: -- Analyze Text: +Analyze Text: - - Intent Recognition - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/intent/main.py) - - Sentiment Analysis - [examples/sentiment/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/sentiment/main.py) - - Summarization - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/summary/main.py) - - Topic Detection - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/topic/main.py) +- Intent Recognition - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/intent/main.py) +- Sentiment Analysis - [examples/sentiment/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/sentiment/main.py) +- Summarization - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/summary/main.py) +- Topic Detection - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/analyze/topic/main.py) +PreRecorded Audio: -- PreRecorded Audio: +- Transcription From an Audio File - [examples/prerecorded/file](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/file/main.py) +- Transcrption From an URL - [examples/prerecorded/url](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/url/main.py) +- Intent Recognition - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/intent/main.py) +- Sentiment Analysis - [examples/sentiment/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/sentiment/main.py) +- Summarization - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/summary/main.py) +- Topic Detection - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/topic/main.py) - - Transcription From an Audio File - [examples/prerecorded/file](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/file/main.py) - - Transcrption From an URL - [examples/prerecorded/url](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/url/main.py) - - Intent Recognition - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/intent/main.py) - - Sentiment Analysis - [examples/sentiment/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/sentiment/main.py) - - Summarization - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/summary/main.py) - - Topic Detection - [examples/analyze/intent](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/prerecorded/topic/main.py) +Live Audio Transcription: -- Live Audio Transcription: +- From a Microphone - [examples/streaming/microphone](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/microphone/main.py) +- From an HTTP Endpoint - [examples/streaming/http](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/http/main.py) - - From a Microphone - [examples/streaming/microphone](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/microphone/main.py) - - From an HTTP Endpoint - [examples/streaming/http](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/streaming/http/main.py) +Management API exercise the full [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations for: -- Management API exercise the full [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations for: - - - Balances - [examples/manage/balances](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/balances/main.py) - - Invitations - [examples/manage/invitations](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/invitations/main.py) - - Keys - [examples/manage/keys](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/keys/main.py) - - Members - [examples/manage/members](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/members/main.py) - - Projects - [examples/manage/projects](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/projects/main.py) - - Scopes - [examples/manage/scopes](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/scopes/main.py) - - Usage - [examples/manage/usage](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/usage/main.py) +- Balances - [examples/manage/balances](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/balances/main.py) +- Invitations - [examples/manage/invitations](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/invitations/main.py) +- Keys - [examples/manage/keys](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/keys/main.py) +- Members - [examples/manage/members](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/members/main.py) +- Projects - [examples/manage/projects](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/projects/main.py) +- Scopes - [examples/manage/scopes](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/scopes/main.py) +- Usage - [examples/manage/usage](https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/manage/usage/main.py) To run each example set the `DEEPGRAM_API_KEY` as an environment variable, then `cd` into each example folder and execute the example: `go run main.py`. - -# Logging +## Logging This SDK provides logging as a means to troubleshoot and debug issues encountered. By default, this SDK will enable `Information` level messages and higher (ie `Warning`, `Error`, etc) when you initialize the library as follows: @@ -222,11 +220,12 @@ config: DeepgramClientOptions = DeepgramClientOptions( ) deepgram: DeepgramClient = DeepgramClient("", config) ``` -# Backwards Compatibility + +## Backwards Compatibility Older SDK versions will receive Priority 1 (P1) bug support only. Security issues, both in our code and dependencies, are promptly addressed. Significant bugs without clear workarounds are also given priority attention. -# Development and Contributing +## Development and Contributing Interested in contributing? We ❤️ pull requests! @@ -234,7 +233,7 @@ To make sure our community is safe for all, be sure to review and agree to our [Code of Conduct](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CODE_OF_CONDUCT.md). Then see the [Contribution](https://github.com/deepgram/deepgram-python-sdk/blob/main/.github/CONTRIBUTING.md) guidelines for more information. -## Prerequisites +### Prerequisites In order to develop new features for the SDK itself, you first need to uninstall any previous installation of the `deepgram-sdk` and then install/pip the dependencies contained in the `requirements.txt` then instruct python (via pip) to use the SDK by installing it locally. @@ -246,7 +245,7 @@ pip install -r requirements.txt pip install -e . ``` -## Testing +### Testing If you are looking to contribute or modify pytest code, then you need to install the following dependencies: @@ -254,7 +253,7 @@ If you are looking to contribute or modify pytest code, then you need to install pip install -r requirements-dev.txt ``` -# Getting Help +## Getting Help We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either: diff --git a/hack/check/check-mdlint.sh b/hack/check/check-mdlint.sh new file mode 100755 index 00000000..a248b4ae --- /dev/null +++ b/hack/check/check-mdlint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o errexit +set -o nounset +set -o pipefail + +# Change directories to the parent directory of the one in which this +# script is located. +cd "$(dirname "${BASH_SOURCE[0]}")/../.." + +# mdlint rules with common errors and possible fixes can be found here: +# https://github.com/igorshubovych/markdownlint-cli +docker run -v "$PWD":/workdir \ + ghcr.io/igorshubovych/markdownlint-cli:latest \ + -i LICENSE \ + "*.md" diff --git a/hack/check/check-shell.sh b/hack/check/check-shell.sh new file mode 100755 index 00000000..f6fb3d4e --- /dev/null +++ b/hack/check/check-shell.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o errexit +set -o nounset +set -o pipefail + +# Change directories to the parent directory of the one in which this +# script is located. +cd "$(dirname "${BASH_SOURCE[0]}")/../.." + +usage() { + cat <&2; exit 1 + ;; + \?) + { echo "invalid option: -${OPTARG}"; usage; } 1>&2; exit 1 + ;; + :) + echo "option -${OPTARG} requires an argument" 1>&2; exit 1 + ;; + esac +done + +shellcheck --version +find . -path ./vendor -prune -o -name "*.*sh" -type f -print0 | xargs -0 shellcheck diff --git a/hack/check/check-yaml.sh b/hack/check/check-yaml.sh new file mode 100755 index 00000000..e1749394 --- /dev/null +++ b/hack/check/check-yaml.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail + +CHECK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +REPO_DIR="$(dirname "${CHECK_DIR}")/.." + +docker run --rm -t cytopia/yamllint --version +CONTAINER_NAME="dg_yamllint_$RANDOM" +docker run --name ${CONTAINER_NAME} -t -v "${REPO_DIR}":/deepgram-go-sdk:ro cytopia/yamllint -s -c /deepgram-go-sdk/.yamllintconfig.yaml /deepgram-go-sdk +EXIT_CODE=$(docker inspect ${CONTAINER_NAME} --format='{{.State.ExitCode}}') +docker rm -f ${CONTAINER_NAME} &> /dev/null + +if [[ ${EXIT_CODE} == "0" ]]; then + echo "yamllint passed!" +else + echo "yamllint exit code ${EXIT_CODE}: YAML linting failed!" + echo "Please fix the listed yamllint errors and verify using 'make yamllint'" + exit "${EXIT_CODE}" +fi diff --git a/hack/ensure-deps/ensure-actionlint.sh b/hack/ensure-deps/ensure-actionlint.sh new file mode 100755 index 00000000..7f0e70ea --- /dev/null +++ b/hack/ensure-deps/ensure-actionlint.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +CI_BUILD="${CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +ACTIONLINT_VERSION="1.6.27" + +SUDO_CMD="sudo" +if [[ "${CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="actionlint" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + curl -LO https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz + mkdir actionlint_${ACTIONLINT_VERSION}_linux_amd64 + mv actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz ./actionlint_${ACTIONLINT_VERSION}_linux_amd64 + pushd "./actionlint_${ACTIONLINT_VERSION}_linux_amd64" || exit 1 + tar -xvf actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz + chmod +x ${CMD} + ${SUDO_CMD} install ./${CMD} /usr/local/bin + popd || exit 1 + rm -rf ./actionlint_${ACTIONLINT_VERSION}_linux_amd64 + rm actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz + ;; + Darwin) + brew install actionlint + ;; +esac +fi diff --git a/hack/ensure-deps/ensure-dependencies.sh b/hack/ensure-deps/ensure-dependencies.sh new file mode 100755 index 00000000..158b8b20 --- /dev/null +++ b/hack/ensure-deps/ensure-dependencies.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +# set -o errexit +set -o nounset +set -o pipefail +set -o xtrace + +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +REPO_PATH="$(git rev-parse --show-toplevel)" + +case "${BUILD_OS}" in + Linux) + ;; + Darwin) + ;; + *) + echo "${BUILD_OS} is unsupported" + exit 1 + ;; +esac + +i=0 + +# these are must have dependencies to just get going +if [[ -z "$(command -v go)" ]]; then + echo "Missing go" + ((i=i+1)) +fi +if [[ -z "$(command -v docker)" ]]; then + echo "Missing docker" + ((i=i+1)) +fi +# these are must have dependencies to just get going + +if [[ $i -gt 0 ]]; then + echo "Total missing: $i" + echo "Please install these minimal dependencies in order to continue" + exit 1 +fi + +"${REPO_PATH}/hack/ensure-deps/ensure-actionlint.sh" +"${REPO_PATH}/hack/ensure-deps/ensure-shellcheck.sh" +"${REPO_PATH}/hack/ensure-deps/ensure-diffutils.sh" +"${REPO_PATH}/hack/ensure-deps/ensure-gh-cli.sh" +"${REPO_PATH}/hack/ensure-deps/ensure-jq.sh" +"${REPO_PATH}/hack/ensure-deps/ensure-portaudio.sh" + +echo "No missing dependencies!" diff --git a/hack/ensure-deps/ensure-diffutils.sh b/hack/ensure-deps/ensure-diffutils.sh new file mode 100755 index 00000000..fd8ede5c --- /dev/null +++ b/hack/ensure-deps/ensure-diffutils.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +_CI_BUILD="${_CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +# VERSION="1.7.1" + +SUDO_CMD="sudo" +if [[ "${_CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="diff3" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + if [[ -f "/etc/redhat-release" ]]; then + ${SUDO_CMD} yum -y install diffutils + elif [[ "$(grep Ubuntu /etc/os-release)" != "" ]]; then + ${SUDO_CMD} apt-get -y install diffutils + else + echo "**** Please install diffutils before proceeding *****" + exit 1 + fi + ;; + Darwin) + brew install diffutils + ;; +esac +fi diff --git a/hack/ensure-deps/ensure-gh-cli.sh b/hack/ensure-deps/ensure-gh-cli.sh new file mode 100755 index 00000000..372a8bbd --- /dev/null +++ b/hack/ensure-deps/ensure-gh-cli.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +CI_BUILD="${CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +VERSION="2.48.0" + +SUDO_CMD="sudo" +if [[ "${CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="gh" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + curl -LO https://github.com/cli/cli/releases/download/v${VERSION}/gh_${VERSION}_linux_amd64.tar.gz + tar -xvf gh_${VERSION}_linux_amd64.tar.gz + pushd "./gh_${VERSION}_linux_amd64/bin" || exit 1 + chmod +x ${CMD} + ${SUDO_CMD} install ./${CMD} /usr/local/bin + popd || exit 1 + rm -rf ./gh_${VERSION}_linux_amd64 + rm gh_${VERSION}_linux_amd64.tar.gz + ;; + Darwin) + brew install gh + ;; +esac +fi diff --git a/hack/ensure-deps/ensure-jq.sh b/hack/ensure-deps/ensure-jq.sh new file mode 100755 index 00000000..492310ab --- /dev/null +++ b/hack/ensure-deps/ensure-jq.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +_CI_BUILD="${_CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +VERSION="1.7.1" + +SUDO_CMD="sudo" +if [[ "${_CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="jq" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + curl -L "https://github.com/stedolan/jq/releases/download/jq-${VERSION}/jq-linux64" -o "jq" + chmod +x jq + ${SUDO_CMD} mv ${CMD} /usr/local/bin + ;; + Darwin) + brew install jq + ;; +esac +fi diff --git a/hack/ensure-deps/ensure-portaudio.sh b/hack/ensure-deps/ensure-portaudio.sh new file mode 100755 index 00000000..c9f3b7b6 --- /dev/null +++ b/hack/ensure-deps/ensure-portaudio.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +_CI_BUILD="${_CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +# VERSION="1.7.1" + +SUDO_CMD="sudo" +if [[ "${_CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="portaudio" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + if [[ -f "/etc/redhat-release" ]]; then + ${SUDO_CMD} yum -y install portaudio19-dev + elif [[ "$(grep Ubuntu /etc/os-release)" != "" ]]; then + ${SUDO_CMD} apt-get -y install portaudio19-dev + else + echo "**** Please install portaudio before proceeding *****" + exit 1 + fi + ;; + Darwin) + brew install portaudio + ;; +esac +fi diff --git a/hack/ensure-deps/ensure-shellcheck.sh b/hack/ensure-deps/ensure-shellcheck.sh new file mode 100755 index 00000000..dc8afb72 --- /dev/null +++ b/hack/ensure-deps/ensure-shellcheck.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +# Copyright 2024 Deepgram SDK contributors. All Rights Reserved. +# Use of this source code is governed by a MIT license that can be found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -o nounset +set -o pipefail +set -o xtrace + +_CI_BUILD="${_CI_BUILD:-""}" +BUILD_OS=$(uname 2>/dev/null || echo Unknown) +# BUILD_ARCH=$(uname -m 2>/dev/null || echo Unknown) +VERSION="0.10.0" + +SUDO_CMD="sudo" +if [[ "${_CI_BUILD}" == "true" ]]; then + SUDO_CMD="" +fi + +CMD="shellcheck" +if [[ -z "$(command -v ${CMD})" ]]; then +echo "Attempting install of ${CMD}..." +case "${BUILD_OS}" in + Linux) + curl -LO https://github.com/koalaman/shellcheck/releases/download/v${VERSION}/shellcheck-v${VERSION}.linux.x86_64.tar.xz + tar -xvf shellcheck-v${VERSION}.linux.x86_64.tar.xz + pushd "./shellcheck-v${VERSION}" || exit 1 + chmod +x ${CMD} + ${SUDO_CMD} install ./${CMD} /usr/local/bin + popd || exit 1 + rm -rf ./shellcheck-v${VERSION} + rm shellcheck-v${VERSION}.linux.x86_64.tar.xz + ;; + Darwin) + # case "${BUILD_ARCH}" in + # x86_64) + # brew install shellcheck + # ;; + # arm64) + # brew install shellcheck + # ;; + # esac + brew install shellcheck + ;; +esac +fi