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
Current release: 0.0.8. Python 3.9+ is required.
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.
Metadata
Release files for link-shortly 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| link_shortly-0.0.8.tar.gz | 8.7 kB | Without provenance | Details for link_shortly-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| link_shortly-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for link_shortly-0.0.8-py3-none-any.whl |
Total release size: 17.9 kB
Release files / link_shortly-0.0.8.tar.gz
| Download URL | link_shortly-0.0.8.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9025eb7fe47ad8fff7b963fe28c413b48e8260a28ba3f7f87665a58e366bf998
|
|
BLAKE2b-256 checksum How to use checksums |
930998e721b708688ea2e88713724dd9a848c3f115147784bf80dce74a77cc3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / link_shortly-0.0.8-py3-none-any.whl
| Download URL | link_shortly-0.0.8-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe6b5cc70f00a1c43efdf8f074b844dd278e64018f8a4516794e88326698b908
|
|
BLAKE2b-256 checksum How to use checksums |
88e174e4ce988d4852f1b5c925ac4c1ecd0cf40b6e49af7e372b8b739ae993c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for link-shortly 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.