-
Notifications
You must be signed in to change notification settings - Fork 0
Prepare for PyPI releases #11
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
8 commits
Select commit
Hold shift + click to select a range
84db83e
Match TS SDK default enforcement mode
nick434434 806ea56
Sync with dev deps to allow usage in workflows
nick434434 c923301
Rename importable package name to supertab_connect
nick434434 a47dac2
Add the publishing workflow
nick434434 06adcfe
Exclude dev files from sdist
nick434434 5d1cbde
Bump the version
nick434434 007be2c
Update pyproject.toml and README.md
nick434434 6184ca7
Add py.typed
nick434434 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,74 @@ | ||
| name: Publish PyPI package | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*.*.*" | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| environment: | ||
| name: pypi-release | ||
| url: https://pypi.org/p/supertab-connect-sdk | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - uses: astral-sh/setup-uv@v5 | ||
| with: | ||
| enable-cache: true | ||
|
|
||
| - name: Validate release tag format | ||
| run: | | ||
| if [[ ! "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then | ||
| echo "Tag '${GITHUB_REF_NAME}' is not valid semver" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Verify tag version matches pyproject.toml | ||
| run: | | ||
| TAG_VERSION="${GITHUB_REF_NAME#v}" | ||
| PACKAGE_VERSION="$(python - <<'PY' | ||
| import tomllib | ||
| with open("pyproject.toml", "rb") as f: | ||
| print(tomllib.load(f)["project"]["version"]) | ||
| PY | ||
| )" | ||
| if [ "${TAG_VERSION}" != "${PACKAGE_VERSION}" ]; then | ||
| echo "Tag version (${TAG_VERSION}) does not match pyproject.toml version (${PACKAGE_VERSION})" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Sync dependencies | ||
| run: uv sync --locked --extra dev | ||
|
|
||
| - name: Check formatting | ||
| run: uv run ruff format --check . | ||
|
|
||
| - name: Run linting | ||
| run: uv run ruff check . | ||
|
|
||
| - name: Run type checking | ||
| run: uv run ty check | ||
|
|
||
| - name: Run tests | ||
| run: uv run pytest | ||
|
|
||
| - name: Build package | ||
| run: | | ||
| rm -rf dist | ||
| uv run python -m build --no-isolation | ||
|
|
||
| - name: Check package metadata | ||
| run: uv run twine check dist/* | ||
|
|
||
| - name: Publish package to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 |
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ __pycache__/ | |
|
|
||
| .venv/ | ||
| venv/ | ||
| .uv-cache/ | ||
|
|
||
| build/ | ||
| 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 |
|---|---|---|
| @@ -1,28 +1,116 @@ | ||
| # Supertab Connect SDK | ||
|
|
||
| Python SDK for Supertab Connect. | ||
| Python SDK for [Supertab Connect](https://www.supertab.co/supertab-connect). | ||
|
|
||
| ## Usage | ||
| Use this package to obtain Supertab license tokens on the customer side and verify | ||
| or enforce them on the merchant side. | ||
|
|
||
| Check the `examples` folder to get the idea of how to use the provided functionality. | ||
| ## Installation | ||
|
|
||
| Dedicated SDK docs portal is coming soon. | ||
| ```bash | ||
| pip install supertab-connect-sdk | ||
| ``` | ||
|
|
||
| Requires Python 3.12 or newer. | ||
|
|
||
| ## Customer Usage | ||
|
|
||
| Obtain a license token for a resource URL: | ||
|
|
||
| ```python | ||
| import asyncio | ||
|
|
||
| from supertab_connect import obtain_license_token | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| token = await obtain_license_token( | ||
| client_id="your_client_id", | ||
| client_secret="your_client_secret", | ||
| resource_url="https://example.com/premium/article", | ||
| ) | ||
|
|
||
| if token is None: | ||
| print("No token required for this usage") | ||
| return | ||
|
|
||
| print(token) | ||
|
|
||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
| The SDK fetches `license.xml` from the resource origin, finds the best matching | ||
| `<content>` entry, and exchanges the client credentials for a license token. | ||
|
|
||
| ## Merchant Usage | ||
|
|
||
| Verify and record license-token usage: | ||
|
|
||
| ```python | ||
| import asyncio | ||
|
|
||
| from supertab_connect import SupertabConnect, SupertabConnectConfig | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| client = SupertabConnect( | ||
| SupertabConnectConfig( | ||
| api_key="your_api_key", | ||
| ) | ||
| ) | ||
|
|
||
| async with client: | ||
| result = await client.verify_and_record( | ||
| token="your.jwt.token", | ||
| resource_url="https://example.com/premium/article", | ||
| user_agent="Mozilla/5.0", | ||
| request_headers={"Accept": "text/html"}, | ||
| ) | ||
|
|
||
| if not result.valid: | ||
| print(f"DENY access: {result.error}") | ||
| return | ||
|
|
||
| print("ALLOW access") | ||
|
|
||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
| For request-level enforcement, use `SupertabConnect.handle_request()` with an | ||
| `httpx.Request`. See the `examples` directory for complete merchant and customer | ||
| examples. | ||
|
|
||
| ## Error Handling | ||
|
|
||
| Customer-side token retrieval raises `SupertabConnectError` when `license.xml` | ||
| cannot be fetched or parsed, no matching content block exists, or the token | ||
| endpoint fails. | ||
|
|
||
| Merchant-side token verification returns typed result objects instead of raising | ||
| for normal invalid-token cases. Invalid tokens include a reason and a human | ||
| readable error. | ||
|
|
||
| ## Typing | ||
|
|
||
| This package ships inline type hints and includes a `py.typed` marker for type | ||
| checkers. | ||
|
|
||
| ## Documentation | ||
|
|
||
| See the [Supertab Connect Python SDK docs](https://supertab-connect.mintlify.app/reference/sdk/python) | ||
| for the full API reference. | ||
|
|
||
| ## Development | ||
|
|
||
| This project uses `hatchling` as the build backend. | ||
|
|
||
| See [DEVELOPMENT.md](DEVELOPMENT.md) for local setup, Git hooks, and CI-aligned development commands. | ||
|
|
||
| ## Package Layout | ||
|
|
||
| ```text | ||
| . | ||
| ├── connect | ||
| │ ├── customer | ||
| │ └── merchant | ||
| ├── examples | ||
| │ ├── obtain_license_token.py | ||
| │ └── obtain_and_verify_license_token.py | ||
| └── tests | ||
| ``` | ||
| ## Links | ||
|
|
||
| - [Documentation](https://supertab-connect.mintlify.app/reference/sdk/python) | ||
| - [Repository](https://github.com/getsupertab/connect-sdk-python) | ||
| - [Issues](https://github.com/getsupertab/connect-sdk-python/issues) | ||
| - [License](LICENSE) |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
File renamed without changes.
File renamed without changes.
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,6 @@ | ||
| """Customer functionality for Supertab Connect.""" | ||
|
|
||
| from supertab_connect.customer.token import obtain_license_token | ||
| from supertab_connect.types import UsageType | ||
|
|
||
| __all__ = ["UsageType", "obtain_license_token"] |
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
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
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
File renamed without changes.
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.