Skip to main content

A simple yet powerful async URL shortener library supporting multiple providers (TinyURL, Bitly, Ouo.io, Adlinkfy, Shareus.io, etc).

PyPI License Downloads

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)

Source distribution for link-shortly 0.0.8
File Size Uploaded
link_shortly-0.0.8.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for link-shortly 0.0.8
File Interpreter ABI Platform
link_shortly-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page