tinyurl-sdk 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ python -m pip install -e .
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ - name: Install build tools
19
+ run: python -m pip install -U pip build
20
+
21
+ - name: Build distributions
22
+ run: python -m build
23
+
24
+ - name: Upload build artifacts
25
+ uses: actions/upload-artifact@v4
26
+ with:
27
+ name: dist
28
+ path: dist/*
29
+
30
+ publish:
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+
34
+ # Trusted Publishing için kritik: id-token izni şart
35
+ permissions:
36
+ id-token: write
37
+ contents: read
38
+
39
+ # (Opsiyonel) PyPI tarafında environment tanımladıysan birebir aynı isim
40
+ environment:
41
+ name: pypi
42
+
43
+ steps:
44
+ - name: Download artifacts
45
+ uses: actions/download-artifact@v4
46
+ with:
47
+ name: dist
48
+ path: dist
49
+
50
+ - name: Publish to PyPI
51
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,20 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ *.egg-info/
7
+ dist/
8
+ build/
9
+
10
+ # Virtual environments
11
+ .venv/
12
+ venv/
13
+ ENV/
14
+
15
+ # Editors
16
+ .vscode/
17
+ .idea/
18
+
19
+ # OS files
20
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: tinyurl-sdk
3
+ Version: 0.1.1
4
+ Summary: Simplifying TinyURL link creation and management with a lightweight Python SDK.
5
+ Project-URL: Homepage, https://github.com/bilalbaraz/tinyurl-sdk
6
+ Project-URL: Repository, https://github.com/bilalbaraz/tinyurl-sdk
7
+ Author-email: Bilal Baraz <bilalbaraz@windowslive.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: sdk,shortener,tinyurl,url
11
+ Requires-Python: >=3.9
12
+ Requires-Dist: httpx>=0.23.0
13
+ Description-Content-Type: text/markdown
14
+
15
+ # tinyurl-sdk
16
+
17
+ A lightweight Python SDK for simplifying TinyURL link creation and management.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install tinyurl-sdk
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```python
28
+ from tinyurl_sdk.client import TinyURLClient
29
+
30
+ client = TinyURLClient(api_key="YOUR_API_KEY")
31
+ short_url = client.shorten(
32
+ url="https://www.example.com/my-really-long-link-that-I-need-to-shorten/84378949",
33
+ domain="tinyurl.com",
34
+ alias="myexamplelink",
35
+ tags="example,link",
36
+ expires_at="2024-10-25 10:11:12",
37
+ description="string",
38
+ )
39
+ print(short_url)
40
+ ```
41
+
42
+ ### Parameters
43
+
44
+ Constructor:
45
+
46
+ | Name | Required | Type | Notes |
47
+ | --- | --- | --- | --- |
48
+ | `api_key` | Yes | `str` | TinyURL API key. |
49
+ | `timeout` | No | `float` | Request timeout in seconds. Default: `10.0`. |
50
+ | `api_base_url` | No | `str` | Base API URL. Default: `https://api.tinyurl.com`. |
51
+ | `user_agent` | No | `str` | User agent header. Default: `tinyurl-sdk/0.0.0`. |
52
+
53
+ `shorten`:
54
+
55
+ | Name | Required | Type | Notes |
56
+ | --- | --- | --- | --- |
57
+ | `url` | Yes | `str` | Long URL to shorten. |
58
+ | `domain` | No | `str` | TinyURL domain. |
59
+ | `alias` | No | `str` | Must be at least 5 characters if provided. |
60
+ | `tags` | No | `str` | Comma-separated tags. |
61
+ | `expires_at` | No | `str` | Expiration timestamp (API format). |
62
+ | `description` | No | `str` | Link description. |
63
+
64
+ ## Development
65
+
66
+ ```bash
67
+ pip install -e .
68
+ ```
69
+
70
+ ## License
71
+
72
+ MIT
@@ -0,0 +1,58 @@
1
+ # tinyurl-sdk
2
+
3
+ A lightweight Python SDK for simplifying TinyURL link creation and management.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install tinyurl-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from tinyurl_sdk.client import TinyURLClient
15
+
16
+ client = TinyURLClient(api_key="YOUR_API_KEY")
17
+ short_url = client.shorten(
18
+ url="https://www.example.com/my-really-long-link-that-I-need-to-shorten/84378949",
19
+ domain="tinyurl.com",
20
+ alias="myexamplelink",
21
+ tags="example,link",
22
+ expires_at="2024-10-25 10:11:12",
23
+ description="string",
24
+ )
25
+ print(short_url)
26
+ ```
27
+
28
+ ### Parameters
29
+
30
+ Constructor:
31
+
32
+ | Name | Required | Type | Notes |
33
+ | --- | --- | --- | --- |
34
+ | `api_key` | Yes | `str` | TinyURL API key. |
35
+ | `timeout` | No | `float` | Request timeout in seconds. Default: `10.0`. |
36
+ | `api_base_url` | No | `str` | Base API URL. Default: `https://api.tinyurl.com`. |
37
+ | `user_agent` | No | `str` | User agent header. Default: `tinyurl-sdk/0.0.0`. |
38
+
39
+ `shorten`:
40
+
41
+ | Name | Required | Type | Notes |
42
+ | --- | --- | --- | --- |
43
+ | `url` | Yes | `str` | Long URL to shorten. |
44
+ | `domain` | No | `str` | TinyURL domain. |
45
+ | `alias` | No | `str` | Must be at least 5 characters if provided. |
46
+ | `tags` | No | `str` | Comma-separated tags. |
47
+ | `expires_at` | No | `str` | Expiration timestamp (API format). |
48
+ | `description` | No | `str` | Link description. |
49
+
50
+ ## Development
51
+
52
+ ```bash
53
+ pip install -e .
54
+ ```
55
+
56
+ ## License
57
+
58
+ MIT
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tinyurl-sdk"
7
+ version = "0.1.1"
8
+ description = "Simplifying TinyURL link creation and management with a lightweight Python SDK."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "Bilal Baraz", email = "bilalbaraz@windowslive.com" }
14
+ ]
15
+ keywords = ["tinyurl", "sdk", "url", "shortener"]
16
+ dependencies = [
17
+ "httpx>=0.23.0"
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/bilalbaraz/tinyurl-sdk"
22
+ Repository = "https://github.com/bilalbaraz/tinyurl-sdk"
@@ -0,0 +1,3 @@
1
+ from .client import TinyURLClient
2
+
3
+ __all__ = ["TinyURLClient"]
@@ -0,0 +1,91 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Optional
5
+
6
+ import httpx
7
+
8
+ from .exceptions import TinyURLClientError, TinyURLHTTPError, TinyURLResponseError
9
+
10
+ @dataclass
11
+ class TinyURLClient:
12
+ api_key: str
13
+ timeout: float = 10.0
14
+ api_base_url: str = "https://api.tinyurl.com"
15
+ user_agent: str = "tinyurl-sdk/0.0.0"
16
+
17
+ def shorten(
18
+ self,
19
+ url: str,
20
+ domain: Optional[str] = None,
21
+ alias: Optional[str] = None,
22
+ tags: Optional[str] = None,
23
+ expires_at: Optional[str] = None,
24
+ description: Optional[str] = None,
25
+ ) -> str:
26
+ """Create a TinyURL short link for the provided long URL."""
27
+ if not url:
28
+ raise ValueError("url is required")
29
+ if alias is not None and len(alias) < 5:
30
+ raise ValueError("alias must be at least 5 characters long")
31
+
32
+ return self._shorten_token(
33
+ url,
34
+ domain=domain,
35
+ alias=alias,
36
+ tags=tags,
37
+ expires_at=expires_at,
38
+ description=description,
39
+ )
40
+
41
+ def _shorten_token(
42
+ self,
43
+ url: str,
44
+ domain: Optional[str] = None,
45
+ alias: Optional[str] = None,
46
+ tags: Optional[str] = None,
47
+ expires_at: Optional[str] = None,
48
+ description: Optional[str] = None,
49
+ ) -> str:
50
+ if not self.api_key:
51
+ raise TinyURLClientError("api_key is required for token API usage")
52
+ if alias is not None and len(alias) < 5:
53
+ raise ValueError("alias must be at least 5 characters long")
54
+
55
+ payload = {"url": url}
56
+ if domain:
57
+ payload["domain"] = domain
58
+ if alias:
59
+ payload["alias"] = alias
60
+ if tags:
61
+ payload["tags"] = tags
62
+ if expires_at:
63
+ payload["expires_at"] = expires_at
64
+ if description:
65
+ payload["description"] = description
66
+
67
+ url = f"{self.api_base_url.rstrip('/')}/create"
68
+ headers = {"Authorization": f"Bearer {self.api_key}"}
69
+
70
+ try:
71
+ with httpx.Client(
72
+ timeout=self.timeout,
73
+ headers={"User-Agent": self.user_agent},
74
+ ) as client:
75
+ response = client.post(url, json=payload, headers=headers)
76
+ response.raise_for_status()
77
+ data = response.json()
78
+ except httpx.HTTPStatusError as exc:
79
+ raise TinyURLHTTPError(
80
+ f"HTTP error {exc.response.status_code}: {exc.response.reason_phrase}"
81
+ ) from exc
82
+ except httpx.RequestError as exc:
83
+ raise TinyURLHTTPError(f"Network error: {exc}") from exc
84
+ except ValueError as exc:
85
+ raise TinyURLResponseError("Token API did not return valid JSON") from exc
86
+
87
+ tiny_url = data.get("data", {}).get("tiny_url")
88
+ if not tiny_url:
89
+ raise TinyURLResponseError("Token API response missing tiny_url")
90
+
91
+ return tiny_url
@@ -0,0 +1,10 @@
1
+ class TinyURLClientError(Exception):
2
+ """Base error for TinyURL client operations."""
3
+
4
+
5
+ class TinyURLHTTPError(TinyURLClientError):
6
+ """Raised when the HTTP layer fails or returns a non-200 response."""
7
+
8
+
9
+ class TinyURLResponseError(TinyURLClientError):
10
+ """Raised when the API response is missing expected fields."""
File without changes