Skip to main content

A Python Client SDK for the Linkup API

Project description

🚀 Linkup Python SDK

PyPI version License: MIT PyPI - Downloads Discord

A Python SDK for the Linkup API, allowing easy integration with Linkup's services in any Python application. 🐍

Checkout the official API documentation and SDK documentation for additional details on how to benefit from Linkup services to the full extent. 📝

🌟 Features

  • Simple and intuitive API client.
  • 🔍 Support all Linkup entrypoints and parameters.
  • Support synchronous and asynchronous calls.
  • 🔒 Handle authentication and request management.

📦 Installation

Simply install the Linkup Python SDK as any Python package, for instance using pip:

pip install linkup-sdk

🛠️ Usage

Setting Up Your Environment

  1. 🔑 Obtain an API Key:

    Sign up on Linkup to get your API key.

  2. ⚙️ Set-up the API Key:

    Option 1: Export the LINKUP_API_KEY environment variable in your shell before using the Python SDK.

    export LINKUP_API_KEY=<your-linkup-api-key>
    

    Option 2: Set the LINKUP_API_KEY environment variable directly within Python, using for instance os.environ or python-dotenv with a .env file (python-dotenv needs to be installed separately in this case), before creating the Linkup Client.

    import os
    from linkup import LinkupClient
    
    os.environ["LINKUP_API_KEY"] = "<your-linkup-api-key>"
    # or dotenv.load_dotenv()
    client = LinkupClient()
    ...
    

    Option 3: Pass the Linkup API key to the Linkup Client when creating it.

    from linkup import LinkupClient
    
    client = LinkupClient(api_key="<your-linkup-api-key>")
    ...
    

📋 Examples

📝 Search

The search function can be used to performs web searches. It supports two very different complexity modes:

  • with depth="standard", the search will be straightforward and fast, suited for relatively simple queries (e.g. "What's the weather in Paris today?")
  • with depth="deep", the search will use an agentic workflow, which makes it in general slower, but it will be able to solve more complex queries (e.g. "What is the company profile of LangChain accross the last few years, and how does it compare to its concurrents?")

The search function also supports three output types:

  • with output_type="searchResults", the search will return a list of relevant documents
  • with output_type="sourcedAnswer", the search will return a concise answer with sources
  • with output_type="structured", the search will return a structured output according to a user-defined schema
from typing import Any

from linkup import LinkupClient, LinkupSourcedAnswer

client = LinkupClient()  # API key can be read from the environment variable or passed as an argument
search_response: Any = client.search(
    query="What are the 3 major events in the life of Abraham Lincoln?",
    depth="deep",  # "standard" or "deep"
    output_type="sourcedAnswer",  # "searchResults" or "sourcedAnswer" or "structured"
    structured_output_schema=None,  # must be filled if output_type is "structured"
)
assert isinstance(search_response, LinkupSourcedAnswer)
print(search_response.model_dump())

Which prints:

{
  answer="The three major events in the life of Abraham Lincoln are: 1. ...",
  sources=[
    {
      "name": "HISTORY",
      "url": "https://www.history.com/topics/us-presidents/abraham-lincoln",
      "snippet": "Abraham Lincoln - Facts & Summary - HISTORY ...",
      "favicon": "https://www.history.com/favicon.ico",
    },
    ...
  ]
}

Check the code or the official documentation for the detailed list of available parameters.

🪝 Fetch

The fetch function can be used to retrieve the content of a given web page in a cleaned up markdown format.

You can use the render_js flag to execute the JavaScript code of the page before returning the content, and ask to include_raw_html to the response if you feel like it.

from linkup import LinkupClient, LinkupFetchResponse

client = LinkupClient()  # API key can be read from the environment variable or passed as an argument
fetch_response: LinkupFetchResponse = client.fetch(
    url="https://docs.linkup.so",
    render_js=False,
    include_raw_html=True,
)
print(fetch_response.model_dump())

Which prints:

{
  markdown="Get started for free, no credit card required...",
  raw_html="<!DOCTYPE html><html lang=\"en\"><head>...</head><body>...</body></html>"
}

Check the code or the official documentation for the detailed list of available parameters.

⌛ Asynchronous Calls

All the Linkup main functions come with an asynchronous counterpart, with the same behavior and the same name prefixed by async_ (e.g. async_search for search). This should be favored in production use cases to avoid blocking the main thread while waiting for the Linkup API to respond. This makes possible to call the Linkup API several times concurrently for instance.

import asyncio
from typing import Any

from linkup import LinkupClient, LinkupSourcedAnswer

async def main() -> None:
    client = LinkupClient()  # API key can be read from the environment variable or passed as an argument
    search_response: Any = await client.async_search(
        query="What are the 3 major events in the life of Abraham Lincoln?",
        depth="deep",  # "standard" or "deep"
        output_type="sourcedAnswer",  # "searchResults" or "sourcedAnswer" or "structured"
        structured_output_schema=None,  # must be filled if output_type is "structured"
    )
    assert isinstance(search_response, LinkupSourcedAnswer)
    print(search_response.model_dump())

asyncio.run(main())

Which prints:

{
  answer="The three major events in the life of Abraham Lincoln are: 1. ...",
  sources=[
    {
      "name": "HISTORY",
      "url": "https://www.history.com/topics/us-presidents/abraham-lincoln",
      "snippet": "Abraham Lincoln - Facts & Summary - HISTORY ..."
      "favicon": "https://www.history.com/favicon.ico",
    },
    ...
  ]
}

📚 More Examples

See the examples/ directory for more examples and documentation, for instance on how to use Linkup entrypoints using asynchronous functions to call the Linkup API several times concurrenly.

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

linkup_sdk-0.12.0.tar.gz (76.1 kB view details)

Uploaded Source

Built Distribution

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

linkup_sdk-0.12.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file linkup_sdk-0.12.0.tar.gz.

File metadata

  • Download URL: linkup_sdk-0.12.0.tar.gz
  • Upload date:
  • Size: 76.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for linkup_sdk-0.12.0.tar.gz
Algorithm Hash digest
SHA256 1ae72141d9576ed7442770d2d4adf65e22351869e97f8efba1250ead5bbfd0a1
MD5 4812a269540ee820f9803be0e9b4170a
BLAKE2b-256 cbbd3b7a03430b25e971cc75242725e44e90373b116926918939a2132c94fed2

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkup_sdk-0.12.0.tar.gz:

Publisher: release.yml on LinkupPlatform/linkup-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file linkup_sdk-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: linkup_sdk-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for linkup_sdk-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f675748ff6ab9ed62ee4e20377e8535f6f5c0bc3fba3b766b89ca0ad101c520
MD5 a2fbea428a1b0fd5ae697ac3a571c157
BLAKE2b-256 571c52dfe0bf0cff747bbde6656293d1cf1eb9906a4b7dabf6fa5f2a994f25a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for linkup_sdk-0.12.0-py3-none-any.whl:

Publisher: release.yml on LinkupPlatform/linkup-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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