Wrapper for the cutt.ly URL shortener API.
Project description
Cuttpy
Wrapper for the Cuttly URL shortener API.
Installation
pip install cuttpy or python -m pip install cuttpy
Make sure to generate an API key by signing up at cutt.ly and by going to the edit account page, https://cutt.ly/edit.
Documentation
This README is the documentation :smile:
Examples
Basic shortener
from cuttpy import Cuttpy
# define shortener
shortener = Cuttpy("YOUR API KEY")
# shorten URL
response = shortener.shorten("https://www.google.com")
# print shortened url
print(response.shortened_url)
Shortener with basic error handling
from cuttpy import Cuttpy
# define shortener
shortener = Cuttpy("YOUR API KEY")
# shorten URL
response = shortener.shorten("https://www.google.com")
try:
# print shortened url
print(response.shortened_url)
# handle AttributeError because the attribute shortened_url does not return if there was an issue shortening the URL
except AttributeError:
print("An error occurred.")
Shortener with advanced error handling
from cuttpy import Cuttpy
# define shortener
shortener = Cuttpy("YOUR API KEY")
# shorten URL
response = shortener.shorten("https://www.google.com")
# check response code and act accordingly
# you can learn what codes there are later in the README
if response.code == 0:
# a response code of 0 means there was a serverside error.
# it is a good idea to also print the http code in this case.
# print the builtin description for the error
print(f"{response.description}\n{response.http}")
elif not response.code == 7:
# print the builtin description for the error
print(response.description)
elif response.code == 7:
# a response code of 7 means there was no error.
# print shortened url
print(response.shortened_url)
Classes
Cuttpy()
The only class worth your time in this library.
Methods:
shorten(url) - Returns a CuttpyResponse() object with everything you need.
CuttpyResponse()
The return type of method Cuttpy().shorten() with various attributes.
Attributes:
Attributes that always return
These attributes always return even if the API fails.
| Name | Description |
|---|---|
| http | The HTTP status code returned by the API. |
| code | The code that the wrapper returns. View what they mean below. |
| description | A hardcoded description for each wrapper code. View what they mean below. |
Wrapper Codes and descriptions
0 - Unknown serverside error
1 - URL has already been shortened
2 - Entered URL is not a URL
3 - Preferred URL name is already taken
4 - Invalid API key.
5 - URL did not pass the validation. Includes invalid characters
6 - URL provided is from a blocked domain
7 - URL has been shortened successfully
Attributes that return only if the URL was shortened.
Title speaks for itself.
| Name | Description |
|---|---|
| original_url | The original URL which was shortened by the API. |
| shortened_url | The shortened version of the original URL. |
Exceptions
This API wrapper uses a system of error codes. View what they mean in the attributes section of the CuttpyResponse() class.
Project details
Release history Release notifications | RSS feed
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 cuttpy-1.1.1.tar.gz.
File metadata
- Download URL: cuttpy-1.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
923cc94abd175e288b9c0c9479e2bd6f1963360f6abc300742f2044398cf1386
|
|
| MD5 |
f682f179085184ca58b3a8db125c8056
|
|
| BLAKE2b-256 |
8c475f7e5fa3e4abb2e6f6794f3057187d458af873cc68fd46e8dc8a2220603e
|
File details
Details for the file cuttpy-1.1.1-py3-none-any.whl.
File metadata
- Download URL: cuttpy-1.1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb69c861449cf96346053880840316f180d8265c8d053f198d94b69141bc8562
|
|
| MD5 |
14989f59ce19130a894e10b92744060c
|
|
| BLAKE2b-256 |
c92f01c365d56eac5fd4f98e8b73ef5bb050ddb431426638da35c830714b300f
|