Skip to main content

LangChain tools for hreflang SEO analysis using hreflang.org API

Project description

LangChain Hreflang Tools

PyPI version Python 3.8+ License: MIT

A comprehensive set of LangChain tools for analyzing hreflang implementation using the hreflang.org API. Perfect for international SEO analysis with AI agents.

🚀 Features

  • Three powerful LangChain tools for hreflang analysis
  • Compatible with CrewAI and any LangChain-based framework
  • Comprehensive hreflang auditing for international websites
  • Sitemap analysis for large-scale SEO audits
  • Account management and usage tracking
  • Detailed error reporting and recommendations

📦 Installation

pip install langchain-hreflang

For development with all extras:

pip install langchain-hreflang[all]

For CrewAI integration:

pip install langchain-hreflang[crewai]

🔑 Setup

  1. Get API Key: Visit hreflang.org, sign up (free), and generate an API key
  2. Set Environment Variable:
    export HREFLANG_API_KEY="your_api_key_here"
    
    Or add to your .env file:
    HREFLANG_API_KEY=your_api_key_here
    

🛠️ Available Tools

1. test_hreflang_urls

Test specific URLs for hreflang implementation.

2. test_hreflang_sitemap

Analyze entire sitemaps for international SEO compliance.

3. check_hreflang_account_status

Monitor your API usage limits and test history.

📚 Usage Examples

Basic LangChain Usage

from langchain_hreflang import test_hreflang_urls, test_hreflang_sitemap

# Test specific URLs
result = test_hreflang_urls.run("https://example.com/en/, https://example.com/es/")
print(result)

# Test entire sitemap
result = test_hreflang_sitemap.run("https://example.com/sitemap.xml")
print(result)

CrewAI Integration

from crewai import Agent, Task, Crew
from langchain_hreflang import hreflang_tools

# Create SEO specialist agent
seo_agent = Agent(
    role="International SEO Specialist",
    goal="Analyze and optimize hreflang implementation for international websites",
    backstory="Expert in international SEO with deep knowledge of hreflang best practices.",
    tools=hreflang_tools,  # All three tools included
    verbose=True
)

# Create analysis task
task = Task(
    description="""
    Analyze the hreflang implementation for https://example.com:
    1. Test the main language versions
    2. Check the sitemap for comprehensive coverage
    3. Identify any implementation issues
    4. Provide specific recommendations
    """,
    agent=seo_agent
)

# Run the analysis
crew = Crew(agents=[seo_agent], tasks=[task])
result = crew.kickoff()

LangChain Agents

from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI
from langchain_hreflang import hreflang_tools

llm = OpenAI(temperature=0)
agent = initialize_agent(
    hreflang_tools,
    llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

result = agent.run("""
Analyze the hreflang implementation for airbnb.com.
Check their main international pages and provide a summary
including any issues found.
""")

🔍 What Gets Analyzed

  • Hreflang tag implementation across language versions
  • Self-declared language detection (<html lang="en">)
  • Bidirectional linking between language versions
  • Return tag errors and missing connections
  • Site-wide statistics for entire domains
  • Broken URLs and loading issues
  • Language coverage analysis

📊 Example Output

Hreflang Test Results (Test ID: abc123...)
Total URLs tested: 3

URL: https://example.com/en/
  Self-declared language: en
  Hreflang links found: 3
    en: https://example.com/en/
    es: https://example.com/es/
    fr: https://example.com/fr/

URL: https://example.com/es/
  Self-declared language: es
  Hreflang links found: 3
    en: https://example.com/en/
    es: https://example.com/es/
    fr: https://example.com/fr/

Issues Found:
  ⚠️  Missing return link from FR to EN version
  ❌  https://example.com/de/ returns 404 error

🎯 Rate Limits

  • Free Tier: 50 URLs per test, 10 tests per day
  • Premium Tier: 1,000 URLs per test, 500 tests per day

Check your limits with check_hreflang_account_status().

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • hreflang.org for providing the excellent hreflang testing API
  • LangChain for the powerful AI agent framework
  • CrewAI for the collaborative AI agent platform

📞 Support


Made with ❤️ for the international SEO and AI community

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

langchain_hreflang-0.1.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

langchain_hreflang-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_hreflang-0.1.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_hreflang-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0290de66950361e85edf3a38aeeb05de674dbfac4a6cb66ae52840e593ebce1c
MD5 243afc1d654f409f69a84fd1685b6266
BLAKE2b-256 15d8d2fcf9309e5b10db5c49de9bcec9a8b9476e8c3b683dc586521d730e0682

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_hreflang-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0880253c1e51424f8173d0817d507a5382e09ace7746b6608c5047c8d694983c
MD5 f9acb68f1940c8967067f311fc20b2ca
BLAKE2b-256 16a706573374ca7d9726a01eae9f23acf22f26d11e9065674c7928dc4321f8da

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