The official Python library makes it easy to integrate Spoo.me’s URL shortening service into your Python applications.
Install the library using pip:
Here’s a simple example to get you started:
Shorten URLs with custom aliases and settings
Get detailed analytics for your shortened URLs
Export your URL data in various formats
Built-in rate limiting to respect API limits
shorten()
Shortens a URL with optional parameters. Returns a shortened URL string.
The URL to shorten. Must be a valid HTTP or HTTPS URL.
Custom alias for the shortened URL. If not provided, a random short code will be generated.
Password protection for the shortened URL. Users will need to enter this password to access the original URL.
Maximum number of clicks allowed for this shortened URL. Once reached, the URL will become inactive.
Whether to block bots from accessing the shortened URL. Default is false
.
emoji_shorten()
Creates emoji-based shortened URLs. Returns a shortened URL string with emojis.
The URL to shorten. Must be a valid HTTP or HTTPS URL.
Custom emoji sequence for the shortened URL. If not provided, random emojis will be used.
Password protection for the shortened URL. Users will need to enter this password to access the original URL.
Maximum number of clicks allowed for this shortened URL. Once reached, the URL will become inactive.
Whether to block bots from accessing the shortened URL. Default is false
.
get_stats()
Retrieves statistics for a shortened URL. Returns a dictionary containing detailed statistics.
The short code of the URL for which to retrieve statistics.
Password if the URL is protected. Required only for password-protected URLs.
export_data()
Exports URL data in various formats. Returns raw data in the specified format.
The short code of the URL for which to export data.
Export format. Supported formats: "json"
, "csv"
, "xlsx"
, "xml"
.
Password if the URL is protected. Required only for password-protected URLs.
The library provides specific error types for different scenarios:
SpooMeError
Base exception class for all Spoo.me related errors.
Attributes:
error_type
: The type of error (e.g., “UrlError”, “AliasError”)message
: Detailed error messagestatus_code
: HTTP status codeUrlError
Raised when the provided URL is invalid or missing.
AliasError
Raised when the requested alias is invalid or already taken.
PasswordError
Raised when the password doesn’t meet requirements.
RateLimitError
Raised when API rate limits are exceeded.
For comprehensive documentation, code examples, and advanced usage patterns, visit the complete library documentation:
Access detailed documentation, API reference, and advanced examples
The library is open source and welcomes contributions:
Contribute to the project, report issues, or suggest improvements
If you encounter any issues with the Python library: