Link-Shortly is a simple Python library to shorten links using the Link-Shortly API or compatible services (like Adlinkfy, GPLinks, etc).
Project description
Link Shortly
Shortly is a simple Python library to shorten links using the Shortly API or compatible services (like Adlinkfy, GPLinks, etc).
Installation
Install link-shortly with pip
pip install link-shortly
To Upgrade
pip install --upgrade link-shortly
Quick Usage Example
from shortly import Shortly
shortly = Shortly(api_key='<YOUR API KEY>', base_url='<YOUR BASE SITE>')
def main():
link = shortly.convert("https://example.com/long-url")
print(link)
if __name__ == "__main__":
main()
Error Handling
The library comes with built-in exception handling to manage common errors such as invalid links, not found links, timeouts, or connection issues.
from shortly import Shortly
from shortly.exceptions import (
ShortlyInvalidLinkError,
ShortlyLinkNotFoundError,
ShortlyTimeoutError,
ShortlyConnectionError,
ShortlyJsonDecodeError,
ShortlyError
)
client = Shortly(api_key="your_api_key", base_url="gplinks.com")
try:
response = client.convert("https://example.com/long-url")
print(f"Shortened Link: {response}")
except ShortlyInvalidLinkError:
print("The provided link is invalid or malformed.")
except ShortlyLinkNotFoundError:
print("The short link does not exist or has expired.")
except ShortlyTimeoutError:
print("The request took too long and timed out.")
except ShortlyConnectionError:
print("Failed to connect to the server.")
except ShortlyJsonDecodeError as e:
print(f"JSON decoding error: {str(e)}")
except ShortlyError as e:
print(f"An error occurred: {e}")
Handling Timeout
If the request takes too long and exceeds the specified timeout, a ShortlyTimeoutError will be raised.
from shortly import Shortly
from shortly.exceptions import ShortlyTimeoutError
client = Shortly(api_key="your_api_key", base_url="gplinks.com")
try:
link = client.convert("https://example.com/long-url", timeout=5)
print(f"Shortened Link: {link}")
except ShortlyTimeoutError:
print("The request took too long and timed out.")
Handling Connection Issues
If there's a problem connecting to the API, a ShortlyConnectionError will be raised.
from shortly import Shortly
from shortly.exceptions import ShortlyConnectionError
client = Shortly(api_key="your_api_key", base_url="gplinks.com")
try:
link = client.convert("https://example.com/long-url")
print(f"Shortened Link: {link}")
except ShortlyConnectionError:
print("Failed to connect to the server.")
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file link_shortly-0.0.3.tar.gz.
File metadata
- Download URL: link_shortly-0.0.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12576f87a50ff510bd81c84581249cf24eb6aec563c4d4714023748859b7b515
|
|
| MD5 |
b9341a32683cc8ea7071585714bbddc8
|
|
| BLAKE2b-256 |
b8d90dd696cb7505fb730ae81343708f12b3c666a1370969eb61591f98149211
|
File details
Details for the file link_shortly-0.0.3-py3-none-any.whl.
File metadata
- Download URL: link_shortly-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec7880174c2d52710ff4067ef4600234f6474e459d6e8a5194cb2f170ed60f68
|
|
| MD5 |
28c3ba2c0ccb4ac71d6fbb86ce5c50cb
|
|
| BLAKE2b-256 |
4888697b27181ab7299659000acd477528f7de21b3065c608aa936cfa8829fef
|