Linkbar Python SDK
A Python client library for the Linkbar API that allows you to create, manage, and track short links.
Installation
pip install linkbar
Quick Start
import linkbar
# Set your API key
linkbar.api_key = "your_api_key_here"
# Create a short link
link = linkbar.Link.create(long_url="https://example.com", domain="linkb.ar")
print(f"Created: {link.short_url}")
print(f"Redirects to: {link.long_url}")
Authentication
Get your API key from your Linkbar dashboard and set it:
import linkbar
linkbar.api_key = "your_api_key_here"
You can also configure the base URL if needed (defaults to https://api.linkbar.co/):
linkbar.base_url = "https://api.linkbar.co/"
Working with Links
Creating Links
# Basic link creation
link = linkbar.Link.create(long_url="https://example.com")
# Create with custom domain
link = linkbar.Link.create(
long_url="https://example.com",
domain="linkb.ar"
)
# Create with custom keyword
link = linkbar.Link.create(
long_url="https://example.com",
domain="linkb.ar",
keyword="my-link"
)
# Create with tags
link = linkbar.Link.create(
long_url="https://example.com",
domain="linkb.ar",
tags=["marketing", "campaign"]
)
Accessing Link Properties
link = linkbar.Link.create(long_url="https://example.com")
print(f"ID: {link.id}")
print(f"Short URL: {link.short_url}")
print(f"Long URL: {link.long_url}")
print(f"Domain: {link.domain_name}")
print(f"Keyword: {link.keyword}")
print(f"Tags: {link.tags}")
print(f"Click count: {link.click_count}")
print(f"Created at: {link.created_at}")
Managing Links
# List all links
links = linkbar.Link.list()
for link in links:
print(f"{link.short_url} -> {link.long_url}")
# Search links
marketing_links = linkbar.Link.list(search="marketing")
# Get a specific link
link = linkbar.Link.get(link_id="abc123")
# Update a link
link.update(long_url="https://newexample.com")
# Add tags to an existing link
link.update(tags=["updated", "new-campaign"])
# Delete a link
link.delete()
# Refresh link data from API
link.refresh()
Working with Domains
Listing Domains
# List all domains (both custom and Linkbar domains)
domains = linkbar.Domain.list()
# List only custom domains
custom_domains = linkbar.Domain.list(is_custom=True)
# Search domains
domains = linkbar.Domain.list(search="example")
Creating Custom Domains
# Create a basic custom domain
domain = linkbar.Domain.create(name="example.com")
# Create domain with redirect URLs
domain = linkbar.Domain.create(
name="example.com",
homepage_redirect_url="https://example.com",
nonexistent_link_redirect_url="https://example.com/404"
)
Managing Domains
# Get a specific domain
domain = linkbar.Domain.get(domain_id="xyz789")
# Access domain properties
print(f"Name: {domain.name}")
print(f"Status: {domain.status}")
print(f"Is custom: {domain.is_custom}")
# Update domain
domain.update(homepage_redirect_url="https://newsite.com")
# Delete domain
domain.delete()
# Refresh domain data
domain.refresh()
Error Handling
import requests
import linkbar
linkbar.api_key = "your_api_key"
try:
link = linkbar.Link.create(long_url="https://example.com")
print(f"Created: {link.short_url}")
except ValueError as e:
# API key not set or missing required parameters
print(f"Configuration error: {e}")
except requests.HTTPError as e:
# API request failed
if e.response.status_code == 401:
print("Invalid API key")
elif e.response.status_code == 400:
print(f"Bad request: {e.response.json()}")
else:
print(f"API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Common Use Cases
Bulk Link Creation
urls_to_shorten = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3"
]
shortened_links = []
for url in urls_to_shorten:
try:
link = linkbar.Link.create(long_url=url, domain="linkb.ar")
shortened_links.append(link)
print(f"✓ {url} -> {link.short_url}")
except Exception as e:
print(f"✗ Failed to shorten {url}: {e}")
Campaign Link Management
# Create campaign links with consistent tagging
campaign_urls = {
"https://example.com/landing": "landing-page",
"https://example.com/pricing": "pricing-page",
"https://example.com/signup": "signup-page"
}
campaign_links = {}
for url, keyword in campaign_urls.items():
link = linkbar.Link.create(
long_url=url,
domain="linkb.ar",
keyword=f"summer-{keyword}",
tags=["summer-campaign", "2024"]
)
campaign_links[keyword] = link
# Later, update all campaign links
for link in campaign_links.values():
link.refresh() # Get updated click counts
print(f"{link.keyword}: {link.click_count} clicks")
API Reference
Link Methods
Link.create(long_url, domain=None, keyword=None, tags=None)- Create a new linkLink.list(search=None)- List links with optional searchLink.get(link_id)- Get a specific link by IDlink.update(long_url=None, domain=None, keyword=None, tags=None)- Update linklink.delete()- Delete linklink.refresh()- Refresh link data from API
Domain Methods
Domain.create(name, homepage_redirect_url=None, nonexistent_link_redirect_url=None)- Create custom domainDomain.list(search=None, is_custom=None)- List domains with optional filtersDomain.get(domain_id)- Get a specific domain by IDdomain.update(name=None, homepage_redirect_url=None, nonexistent_link_redirect_url=None)- Update domaindomain.delete()- Delete domaindomain.refresh()- Refresh domain data from API
Link Properties
id- Unique link identifiershort_url- Full short URL (e.g., "https://linkb.ar/abc123")pretty_url- Short URL without protocol (e.g., "linkb.ar/abc123")long_url- Original URL being shortenedkeyword- Short link keyword/slugdomain- Domain object or stringdomain_name- Domain name as stringtags- List of tagsclick_count- Number of clicks (read-only)created_at- Creation timestamp
Domain Properties
id- Unique domain identifiername- Domain nameis_custom- Whether it's a custom domainstatus- Domain status (pending, connected, disconnected)organization- Associated organizationhomepage_redirect_url- URL for domain root redirectsnonexistent_link_redirect_url- URL for 404 redirects
Requirements
- Python 3.7+
- requests >= 2.25.0
License
MIT License
Metadata
Release files for linkbar 1.0.0
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 |
|---|---|---|---|---|
| linkbar-1.0.0.tar.gz | 13.2 kB | Without provenance | Details for linkbar-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| linkbar-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for linkbar-1.0.0-py3-none-any.whl |
Total release size: 27.3 kB
Release files / linkbar-1.0.0.tar.gz
| Download URL | linkbar-1.0.0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2cc4a7e5085a915d395903b20450076f4068a05fbb1720b9cb4c57a02f3f61f5
|
|
BLAKE2b-256 checksum How to use checksums |
b987f3693ee4f8de2f51c36bb21431e3565b2747256a933024688f433ffc0f96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / linkbar-1.0.0-py3-none-any.whl
| Download URL | linkbar-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ca308c0ccc41710d419b33b8a493cb4ad860c53cd4702d046c746dee8ae7882
|
|
BLAKE2b-256 checksum How to use checksums |
5721ee0577912130fa5fa1a9758b06051230ce916ac4f6ff7da41429e313e454
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for linkbar 1.0.0
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.