Skip to main content

Multithreaded concurrent da.gd URL shortener with in-memory cache

Project description

dagdshort

dagdshort is a Python based multithreaded URL shortener with a memory-cache. It uses the da.gd service.

As a disclaimer, this is an unofficial package and it has no association with da.gd. If you use this package extensively, making a financial donation to da.gd is encouraged.

Other operations are outside the scope of this package.

cicd badge

Links

Caption Link
Repo https://github.com/impredicative/dagdshort/
Changelog https://github.com/impredicative/dagdshort/releases
Package https://pypi.org/project/dagdshort/

Requirements

Python

Python ≥3.9 is required. Any older version of Python will not work.

Usage

To install the package, run:

$ pip install dagdshort

Usage examples:

>>> import dagdshort

# Setup
>>> shortener = dagdshort.Shortener(user_agent_suffix='<YourGitUsername>/<YourGitRepoName>', max_cache_size=256)

# Shorten
>>> long_urls = ['https://www.amazon.com/gp/product/B07LFJMS2S/', 'https://www.cnn.com/election/2020', 'https://paperswithcode.com/sota']
>>> shortener.shorten_urls(long_urls)
{'https://www.amazon.com/gp/product/B07LFJMS2S/': 'https://amzn.to/3Inxf9V', 
'https://www.cnn.com/election/2020': 'https://cnn.it/3FKKZd8',
'https://paperswithcode.com/sota': 'https://bit.ly/3tLlp5w'}

# Show cache info
>>> shortener.cache_info
{'Shortener._shorten_url': CacheInfo(hits=0, misses=3, maxsize=256, currsize=3)}

To obtain the fastest response, URLs must be shortened together in a batch as in the examples above. Up to 8 concurrent workers are automatically used. The max limit can, if really necessary, be changed by setting config.MAX_WORKERS before initializing the shortener.

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

dagdshort-0.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dagdshort-0.1.0-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file dagdshort-0.1.0.tar.gz.

File metadata

  • Download URL: dagdshort-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for dagdshort-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dcd5de3d00541a3d7fcd7690b2cb1ad01860012fbd4d105543d157f2a5e144f0
MD5 1bc6ea58d093822889f258cb1fb1a0dd
BLAKE2b-256 2d05683bd2631d1af737c8256f0448da841d81a82ae70f75fdcd08ec5d4db9ac

See more details on using hashes here.

File details

Details for the file dagdshort-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dagdshort-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for dagdshort-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4bf6d683a9d2c3e05290088af6760e8941651068acab85ffe9a8eaad72688f
MD5 13e9145fc1514d2712b6b9695a55f2ab
BLAKE2b-256 9fdc1c9bafbdcf54b43bb971d7a8ebc971177b6f1d0a6e6bb8bca856cab04ade

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page