speedyshortpy 0.1.0__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,17 @@
1
+ Prosperity Public License 3.0.0
2
+
3
+ Permission is hereby granted, free of charge, to any person or organization
4
+ obtaining a copy of this software and associated documentation files (the
5
+ “Software”), to use, copy, modify, merge, publish, and/or distribute the
6
+ Software for noncommercial purposes only.
7
+
8
+ Noncommercial purposes include educational, personal, research, and open
9
+ source use.
10
+
11
+ Commercial use of this Software, including but not limited to using,
12
+ offering for sale, incorporating into a paid service, or distributing for
13
+ commercial gain, requires a commercial license from the copyright holder.
14
+
15
+ The Software is provided “as is”, without warranty of any kind, express or
16
+ implied, including but not limited to warranties of merchantability, fitness
17
+ for a particular purpose and noninfringement.
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: speedyshortpy
3
+ Version: 0.1.0
4
+ Summary: Python client for the SpeedyShort URL shortener.
5
+ Author: Mauronofrio Matarrese
6
+ License: Prosperity Public License 3.0.0
7
+ Project-URL: Homepage, https://github.com/mauronofrio/SpeedyShort
8
+ Project-URL: Repository, https://github.com/mauronofrio/SpeedyShort
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.28
13
+ Dynamic: license-file
14
+
15
+ # speedyshortpy
16
+
17
+ `speedyshortpy` is a small Python client for the [SpeedyShort](https://github.com/mauronofrio/SpeedyShort)
18
+ URL shortener.
19
+
20
+ It provides a thin wrapper around the HTTP API so you can create short links from Python
21
+ code with a single call.
22
+
23
+ ## Installation
24
+
25
+ Once published on PyPI:
26
+
27
+ ```bash
28
+ pip install speedyshortpy
29
+ ```
30
+
31
+ For local development, you can install it from the cloned repository:
32
+
33
+ ```bash
34
+ pip install -e .
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ By default the client targets a local SpeedyShort instance on `http://localhost:8080`:
40
+
41
+ ```python
42
+ from speedyshortpy import SpeedyShortClient
43
+
44
+ client = SpeedyShortClient() # base_url="http://localhost:8080"
45
+
46
+ result = client.shorten("https://www.example.com")
47
+ print(result.code)
48
+ print(result.short_url)
49
+ print(result.target_url)
50
+ ```
51
+
52
+ You can also point it to a remote instance, for example the public demo:
53
+
54
+ ```python
55
+ client = SpeedyShortClient(base_url="https://syrt.cc")
56
+ ```
57
+
58
+ ### Resolving a short code
59
+
60
+ You usually do not need a client for redirects, but if you want to inspect
61
+ the redirect response:
62
+
63
+ ```python
64
+ resp = client.resolve("a7X9pQ", follow_redirects=False)
65
+ print(resp.status_code)
66
+ print(resp.headers.get("Location"))
67
+ ```
68
+
69
+ ## License
70
+
71
+ This client library is released under the same license as the main project:
72
+ **Prosperity Public License 3.0.0**.
73
+
74
+ Commercial use requires a commercial license from the copyright holder.
@@ -0,0 +1,60 @@
1
+ # speedyshortpy
2
+
3
+ `speedyshortpy` is a small Python client for the [SpeedyShort](https://github.com/mauronofrio/SpeedyShort)
4
+ URL shortener.
5
+
6
+ It provides a thin wrapper around the HTTP API so you can create short links from Python
7
+ code with a single call.
8
+
9
+ ## Installation
10
+
11
+ Once published on PyPI:
12
+
13
+ ```bash
14
+ pip install speedyshortpy
15
+ ```
16
+
17
+ For local development, you can install it from the cloned repository:
18
+
19
+ ```bash
20
+ pip install -e .
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ By default the client targets a local SpeedyShort instance on `http://localhost:8080`:
26
+
27
+ ```python
28
+ from speedyshortpy import SpeedyShortClient
29
+
30
+ client = SpeedyShortClient() # base_url="http://localhost:8080"
31
+
32
+ result = client.shorten("https://www.example.com")
33
+ print(result.code)
34
+ print(result.short_url)
35
+ print(result.target_url)
36
+ ```
37
+
38
+ You can also point it to a remote instance, for example the public demo:
39
+
40
+ ```python
41
+ client = SpeedyShortClient(base_url="https://syrt.cc")
42
+ ```
43
+
44
+ ### Resolving a short code
45
+
46
+ You usually do not need a client for redirects, but if you want to inspect
47
+ the redirect response:
48
+
49
+ ```python
50
+ resp = client.resolve("a7X9pQ", follow_redirects=False)
51
+ print(resp.status_code)
52
+ print(resp.headers.get("Location"))
53
+ ```
54
+
55
+ ## License
56
+
57
+ This client library is released under the same license as the main project:
58
+ **Prosperity Public License 3.0.0**.
59
+
60
+ Commercial use requires a commercial license from the copyright holder.
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "speedyshortpy"
3
+ version = "0.1.0"
4
+ description = "Python client for the SpeedyShort URL shortener."
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ license = {text = "Prosperity Public License 3.0.0"}
8
+ authors = [
9
+ {name = "Mauronofrio Matarrese"}
10
+ ]
11
+
12
+ dependencies = ["requests>=2.28"]
13
+
14
+ [project.urls]
15
+ Homepage = "https://github.com/mauronofrio/SpeedyShort"
16
+ Repository = "https://github.com/mauronofrio/SpeedyShort"
17
+
18
+ [build-system]
19
+ requires = ["setuptools>=68", "wheel"]
20
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ """
2
+ Python client for the SpeedyShort URL shortener.
3
+ """
4
+
5
+ from .client import SpeedyShortClient, ShortLink
6
+
7
+ __all__ = ["SpeedyShortClient", "ShortLink"]
@@ -0,0 +1,81 @@
1
+ """
2
+ Client wrapper for the SpeedyShort URL shortener API.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ from dataclasses import dataclass
8
+ from typing import Optional
9
+
10
+ import requests
11
+
12
+
13
+ @dataclass
14
+ class ShortLink:
15
+ """Represents a short link created by SpeedyShort."""
16
+
17
+ code: str
18
+ short_url: str
19
+ target_url: str
20
+
21
+
22
+ class SpeedyShortClient:
23
+ """
24
+ Simple client for the SpeedyShort HTTP API.
25
+
26
+ By default it targets a local instance running on http://localhost:8080,
27
+ but you can point it to any reachable SpeedyShort installation, for example:
28
+
29
+ client = SpeedyShortClient(base_url="https://syrt.cc")
30
+ """
31
+
32
+ def __init__(
33
+ self,
34
+ base_url: str = "http://localhost:8080",
35
+ timeout: float = 5.0,
36
+ ) -> None:
37
+ self.base_url = base_url.rstrip("/")
38
+ self.timeout = timeout
39
+ self._session = requests.Session()
40
+
41
+ @property
42
+ def session(self) -> requests.Session:
43
+ return self._session
44
+
45
+ def shorten(self, url: str) -> ShortLink:
46
+ """
47
+ Create a short link for the given URL.
48
+
49
+ :param url: The original long URL.
50
+ :return: ShortLink with code, short URL and target URL.
51
+ :raises requests.HTTPError: if the API returns an error.
52
+ """
53
+ endpoint = f"{self.base_url}/api/shorten"
54
+ resp = self._session.post(
55
+ endpoint,
56
+ json={"url": url},
57
+ timeout=self.timeout,
58
+ )
59
+ resp.raise_for_status()
60
+ data = resp.json()
61
+ return ShortLink(
62
+ code=data["code"],
63
+ short_url=data["short_url"],
64
+ target_url=data["target_url"],
65
+ )
66
+
67
+ def resolve(self, code: str, follow_redirects: bool = False) -> requests.Response:
68
+ """
69
+ Perform a GET request for the given short code.
70
+
71
+ This is mostly useful if you want to inspect the redirect response.
72
+ If follow_redirects is False, the Response will usually have status_code 301/302
73
+ and the target URL in the 'Location' header.
74
+
75
+ :param code: Short code (e.g. 'a7X9pQ').
76
+ :param follow_redirects: Whether to follow redirects automatically.
77
+ :return: requests.Response
78
+ """
79
+ url = f"{self.base_url}/{code.lstrip('/')}"
80
+ resp = self._session.get(url, timeout=self.timeout, allow_redirects=follow_redirects)
81
+ return resp
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: speedyshortpy
3
+ Version: 0.1.0
4
+ Summary: Python client for the SpeedyShort URL shortener.
5
+ Author: Mauronofrio Matarrese
6
+ License: Prosperity Public License 3.0.0
7
+ Project-URL: Homepage, https://github.com/mauronofrio/SpeedyShort
8
+ Project-URL: Repository, https://github.com/mauronofrio/SpeedyShort
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests>=2.28
13
+ Dynamic: license-file
14
+
15
+ # speedyshortpy
16
+
17
+ `speedyshortpy` is a small Python client for the [SpeedyShort](https://github.com/mauronofrio/SpeedyShort)
18
+ URL shortener.
19
+
20
+ It provides a thin wrapper around the HTTP API so you can create short links from Python
21
+ code with a single call.
22
+
23
+ ## Installation
24
+
25
+ Once published on PyPI:
26
+
27
+ ```bash
28
+ pip install speedyshortpy
29
+ ```
30
+
31
+ For local development, you can install it from the cloned repository:
32
+
33
+ ```bash
34
+ pip install -e .
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ By default the client targets a local SpeedyShort instance on `http://localhost:8080`:
40
+
41
+ ```python
42
+ from speedyshortpy import SpeedyShortClient
43
+
44
+ client = SpeedyShortClient() # base_url="http://localhost:8080"
45
+
46
+ result = client.shorten("https://www.example.com")
47
+ print(result.code)
48
+ print(result.short_url)
49
+ print(result.target_url)
50
+ ```
51
+
52
+ You can also point it to a remote instance, for example the public demo:
53
+
54
+ ```python
55
+ client = SpeedyShortClient(base_url="https://syrt.cc")
56
+ ```
57
+
58
+ ### Resolving a short code
59
+
60
+ You usually do not need a client for redirects, but if you want to inspect
61
+ the redirect response:
62
+
63
+ ```python
64
+ resp = client.resolve("a7X9pQ", follow_redirects=False)
65
+ print(resp.status_code)
66
+ print(resp.headers.get("Location"))
67
+ ```
68
+
69
+ ## License
70
+
71
+ This client library is released under the same license as the main project:
72
+ **Prosperity Public License 3.0.0**.
73
+
74
+ Commercial use requires a commercial license from the copyright holder.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ speedyshortpy/__init__.py
5
+ speedyshortpy/client.py
6
+ speedyshortpy.egg-info/PKG-INFO
7
+ speedyshortpy.egg-info/SOURCES.txt
8
+ speedyshortpy.egg-info/dependency_links.txt
9
+ speedyshortpy.egg-info/requires.txt
10
+ speedyshortpy.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests>=2.28
@@ -0,0 +1 @@
1
+ speedyshortpy