-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add first SDK implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3c27d6e
feat: add basic SDK
AdirAmsalem 8b14459
fix: cancellation, file i/o, simplifications
AdirAmsalem 0300ed9
chore: include py.typed file in wheel distribution
AdirAmsalem 09948f2
feat: add realtime
AdirAmsalem 28093d8
chore: add uv for dependency management
AdirAmsalem ed35008
add gh workflow
AdirAmsalem fb00c8c
fix formatting
AdirAmsalem 8ab56cd
fix python 3.9
AdirAmsalem 43c4731
chore: support python 3.13
AdirAmsalem 9908d9a
chore: update license format in pyproject.toml
AdirAmsalem 9ce0a6b
chore: test with python 3.14
AdirAmsalem a1f7889
realtime: remove logs
AdirAmsalem 8ffa25a
fix p1 comments
AdirAmsalem f37439f
feat: integrate aiofiles for asynchronous file handling and update de…
AdirAmsalem a11cb3b
style: apply black formatting
AdirAmsalem bc5e909
style: remove unused imports (ruff)
AdirAmsalem f901b41
fix: update examples to use context manager and match refactored API
AdirAmsalem 59446a9
style: apply black formatting to examples
AdirAmsalem ea22b83
docs: update README examples to use DecartClient with context manager
AdirAmsalem a375b62
chore: cleanups according to cr
AdirAmsalem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint & Format Check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install UV | ||
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| - name: Add UV to PATH | ||
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Set up Python 3.12 | ||
| run: uv python install 3.12 | ||
|
|
||
| - name: Install dependencies | ||
| run: uv sync --all-extras | ||
|
|
||
| - name: Check formatting with Black | ||
| run: uv run black --check decart_sdk/ tests/ examples/ | ||
|
|
||
| - name: Lint with Ruff | ||
| run: uv run ruff check decart_sdk/ tests/ examples/ | ||
|
|
||
| - name: Type check with MyPy | ||
| run: uv run mypy decart_sdk/ | ||
| continue-on-error: true # Don't fail on type errors yet | ||
|
|
||
| test: | ||
| name: Test Python ${{ matrix.python-version }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install UV | ||
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| - name: Add UV to PATH | ||
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| run: uv python install ${{ matrix.python-version }} | ||
|
|
||
| - name: Install dependencies | ||
| run: uv sync --all-extras | ||
|
|
||
| - name: Run tests | ||
| run: uv run pytest tests/ -v --cov=decart_sdk --cov-report=xml --cov-report=term | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v4 | ||
| if: matrix.python-version == '3.12' | ||
| with: | ||
| file: ./coverage.xml | ||
| flags: unittests | ||
| name: codecov-umbrella | ||
| fail_ci_if_error: false | ||
|
|
||
| test-examples: | ||
| name: Test Examples (Syntax Check) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install UV | ||
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| - name: Add UV to PATH | ||
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Set up Python 3.12 | ||
| run: uv python install 3.12 | ||
|
|
||
| - name: Install dependencies | ||
| run: uv sync --all-extras | ||
|
|
||
| - name: Check examples for syntax errors | ||
| run: | | ||
| echo "Checking examples compile without syntax errors..." | ||
| uv run python -m py_compile examples/process_video.py | ||
| uv run python -m py_compile examples/process_image.py | ||
| uv run python -m py_compile examples/realtime_synthetic.py | ||
| uv run python -m py_compile examples/realtime_file.py | ||
| echo "✅ All examples have valid syntax" | ||
|
|
||
| # Note: Examples require DECART_API_KEY to actually run | ||
| # They are only syntax-checked in CI | ||
|
|
||
| build: | ||
| name: Build Package | ||
| runs-on: ubuntu-latest | ||
| needs: [lint, test] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Install UV | ||
| run: curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| - name: Add UV to PATH | ||
| run: echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Set up Python 3.12 | ||
| run: uv python install 3.12 | ||
|
|
||
| - name: Build package | ||
| run: uv build | ||
|
|
||
| - name: Check package | ||
| run: | | ||
| uv run pip install twine | ||
| uv run twine check dist/* | ||
|
|
||
| - name: Upload artifacts | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: dist | ||
| path: dist/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| env/ | ||
| ENV/ | ||
| .venv/ | ||
| .venv | ||
|
|
||
| # UV | ||
| .python-version | ||
|
|
||
| # IDEs | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # Testing | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
|
|
||
| # Type checking | ||
| .mypy_cache/ | ||
| .dmypy.json | ||
| dmypy.json | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Project specific | ||
| *.mp4 | ||
| *.mov | ||
| *.png | ||
| *.jpg | ||
| *.jpeg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Decart Python SDK | ||
|
|
||
| A Python SDK for Decart's models. | ||
|
|
||
| ## Installation | ||
|
|
||
| ### Using UV | ||
|
|
||
| ```bash | ||
| uv pip install decart-sdk | ||
| ``` | ||
|
|
||
| ### Using pip | ||
|
|
||
| ```bash | ||
| pip install decart-sdk | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| For complete documentation, guides, and examples, visit: | ||
| **https://docs.platform.decart.ai/sdks/python** | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Process Files | ||
|
|
||
| ```python | ||
| import asyncio | ||
| import os | ||
| from decart_sdk import DecartClient, models | ||
|
|
||
| async def main(): | ||
| async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client: | ||
| # Generate a video from text | ||
| result = await client.process({ | ||
| "model": models.video("lucy-pro-t2v"), | ||
| "prompt": "A cat walking in a lego world", | ||
| }) | ||
|
|
||
| # Save the result | ||
| with open("output.mp4", "wb") as f: | ||
| f.write(result) | ||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
| ### Video Transformation | ||
|
|
||
| ```python | ||
| async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client: | ||
| # Transform a video file | ||
| with open("input.mp4", "rb") as video_file: | ||
| result = await client.process({ | ||
| "model": models.video("lucy-pro-v2v"), | ||
| "prompt": "Anime style with vibrant colors", | ||
| "data": video_file, | ||
| "enhance_prompt": True, | ||
| }) | ||
|
|
||
| # Save the result | ||
| with open("output.mp4", "wb") as f: | ||
| f.write(result) | ||
| ``` | ||
|
|
||
| ## Development | ||
|
|
||
| ### Setup with UV | ||
|
|
||
| ```bash | ||
| # Clone the repository | ||
| git clone https://github.com/decartai/decart-python | ||
| cd decart-python | ||
|
|
||
| # Install UV | ||
| curl -LsSf https://astral.sh/uv/install.sh | sh | ||
|
|
||
| # Install all dependencies (including dev dependencies) | ||
| uv sync --all-extras | ||
|
|
||
| # Run tests | ||
| uv run pytest | ||
|
|
||
| # Run linting | ||
| uv run ruff check decart_sdk/ | ||
|
|
||
| # Format code | ||
| uv run black decart_sdk/ tests/ examples/ | ||
|
|
||
| # Type check | ||
| uv run mypy decart_sdk/ | ||
| ``` | ||
|
|
||
| ### Common Commands | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| uv sync --all-extras | ||
|
|
||
| # Run tests with coverage | ||
| uv run pytest --cov=decart_sdk --cov-report=html | ||
|
|
||
| # Run examples | ||
| uv run python examples/process_video.py | ||
| uv run python examples/realtime_synthetic.py | ||
|
|
||
| # Update dependencies | ||
| uv lock --upgrade | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from .client import DecartClient | ||
| from .errors import ( | ||
| DecartSDKError, | ||
| InvalidAPIKeyError, | ||
| InvalidBaseURLError, | ||
| InvalidInputError, | ||
| ModelNotFoundError, | ||
| ProcessingError, | ||
| WebRTCError, | ||
| ) | ||
| from .models import models, ModelDefinition | ||
| from .types import FileInput, ModelState, Prompt | ||
|
|
||
| try: | ||
| from .realtime import ( | ||
| RealtimeClient, | ||
| RealtimeConnectOptions, | ||
| ConnectionState, | ||
| ) | ||
|
|
||
| REALTIME_AVAILABLE = True | ||
| except ImportError: | ||
| REALTIME_AVAILABLE = False | ||
| RealtimeClient = None # type: ignore | ||
| RealtimeConnectOptions = None # type: ignore | ||
| ConnectionState = None # type: ignore | ||
|
|
||
| __version__ = "0.0.1" | ||
|
|
||
| __all__ = [ | ||
| "DecartClient", | ||
| "DecartSDKError", | ||
| "InvalidAPIKeyError", | ||
| "InvalidBaseURLError", | ||
| "InvalidInputError", | ||
| "ModelNotFoundError", | ||
| "ProcessingError", | ||
| "WebRTCError", | ||
| "models", | ||
| "ModelDefinition", | ||
| "FileInput", | ||
| "ModelState", | ||
| "Prompt", | ||
| ] | ||
|
|
||
| if REALTIME_AVAILABLE: | ||
| __all__.extend( | ||
| [ | ||
| "RealtimeClient", | ||
| "RealtimeConnectOptions", | ||
| "ConnectionState", | ||
| ] | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.