Link-Shortly is a simple Python library to shorten links using the Link-Shortly API or compatible services
Project description
Link Shortly
A simple yet powerful async URL shortener library supporting multiple providers (TinyURL, Bitly, Ouo.io, Adlinkfy, Shareus.io, etc).
Installation
Install link-shortly with pip
pip install link-shortly
To Upgrade
pip install --upgrade link-shortly
Quick Usage Example ( supports sync )
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()
Quick Usage Example ( supports async )
import asyncio
from shortly import Shortly
# Initialize Shortly
shortly = Shortly(api_key='<YOUR API KEY>', base_url='<YOUR BASE SITE>')
async def main():
# Async call to convert URL
link = await shortly.convert("https://example.com/long-url")
print(link)
if __name__ == "__main__":
asyncio.run(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.errors 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.errors 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.errors 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.")
Supported Sites
adlinkfy all sites support shareus support ouo support bitly support tinyurl support request your shortner sites Support
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.7.tar.gz.
File metadata
- Download URL: link_shortly-0.0.7.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa82917a65c71e9679b41f4a7dc4699a81221dacc168135513b6a9f40c9d1a84
|
|
| MD5 |
d07fa54b95d06cb39308cc2509a8fd16
|
|
| BLAKE2b-256 |
8a83980104f2e8c0fc175f3cce962cd984df025558819c95d111ae57bace66d7
|
File details
Details for the file link_shortly-0.0.7-py3-none-any.whl.
File metadata
- Download URL: link_shortly-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a57cbbe0af4e6dba081a7abbc24510e6d47eb85cf8b454d2d36888257081e677
|
|
| MD5 |
605e1a56e4afb712c42a9eb90f10a16f
|
|
| BLAKE2b-256 |
2df2b0c302b31ba1cf9f3848a69af442afe7a7f64bd3505068ed02c3d893768c
|