Skip to main content

This package helps administrators of Forgejo (or Git hosting platforms) generate clear, actionable anti-crawling measures by analyzing user-provided text inputs. When given a description of suspicious

Project description

forgejo-bot-guard

PyPI version License: MIT Downloads LinkedIn

forgejo-bot-guard helps Forgejo (or any self‑hosted Git service) administrators quickly generate clear, actionable anti‑crawling measures.
Provide a description of suspicious bot activity, scraping attempts, or AI‑crawler patterns, and the package returns a structured list of prioritized technical fixes (e.g., robots.txt rules, HTTP headers, CAPTCHA settings) together with short explanations and trade‑off warnings. The library focuses on the most relevant safeguards for Forgejo’s environment, so you can deploy protections without digging through documentation.

Features

  • 📋 Input: free‑form text describing suspicious activity.
  • 🤖 Processing: uses a language model (default ChatLLM7) to extract a concise, regex‑validated response.
  • 🚀 Output: a list of recommended anti‑crawling measures, ordered by priority, with brief rationale and cautions.
  • 🔧 Extensible: plug in any LangChain‑compatible LLM (OpenAI, Anthropic, Google, etc.) if you prefer.

Installation

pip install forgejo_bot_guard

Quick Start

from forgejo_bot_guard import forgejo_bot_guard

# Example user description of a bot that repeatedly hits the API.
description = """
Our API endpoint `/api/v1/repos` is being hammered by an unknown script.
It repeats the same GET request every 2 seconds from many IPs, causing
high load and occasional timeouts.
"""

# Use the default ChatLLM7 (requires LLM7_API_KEY env var or explicit key)
recommendations = forgejo_bot_guard(
    user_input=description,
)

print("\n".join(recommendations))

Using a custom LLM

If you prefer a different language model, pass a LangChain BaseChatModel instance:

OpenAI

from langchain_openai import ChatOpenAI
from forgejo_bot_guard import forgejo_bot_guard

llm = ChatOpenAI()
response = forgejo_bot_guard(user_input=description, llm=llm)

Anthropic

from langchain_anthropic import ChatAnthropic
from forgejo_bot_guard import forgejo_bot_guard

llm = ChatAnthropic()
response = forgejo_bot_guard(user_input=description, llm=llm)

Google Generative AI

from langchain_google_genai import ChatGoogleGenerativeAI
from forgejo_bot_guard import forgejo_bot_guard

llm = ChatGoogleGenerativeAI()
response = forgejo_bot_guard(user_input=description, llm=llm)

Providing an API key for ChatLLM7

ChatLLM7 can be used without passing a key explicitly – it will read LLM7_API_KEY from the environment.
If you want to supply the key directly:

response = forgejo_bot_guard(
    user_input=description,
    api_key="YOUR_LLM7_API_KEY"
)

You can obtain a free API key by registering at https://token.llm7.io/.

API Reference

forgejo_bot_guard(
    user_input: str,
    llm: Optional[BaseChatModel] = None,
    api_key: Optional[str] = None
) -> List[str]
Parameter Type Description
user_input str The free‑form text describing the suspicious bot or scraping activity you want to analyse.
llm Optional[BaseChatModel] A LangChain LLM instance. If omitted, the function creates a ChatLLM7 instance using the provided api_key or the LLM7_API_KEY environment variable.
api_key Optional[str] API key for ChatLLM7. Ignored when a custom llm is supplied. If not given, the function falls back to the LLM7_API_KEY environment variable.

How It Works

  1. Prompt Construction – The package builds a system prompt describing the desired output format and a human prompt containing the user_input.
  2. LLM Call – The selected LLM generates a response that must match a predefined regular expression (pattern).
  3. Validationllmatch validates the response; if it conforms, the extracted list of recommendations is returned.
  4. Error Handling – If the LLM call fails or the output does not match the pattern, a RuntimeError is raised with a descriptive message.

Rate Limits

  • The free tier of LLM7 offers generous limits for typical Forgejo‑admin use cases.
  • For higher throughput, provide your own api_key or switch to a different model via the llm argument.

Contributing

Issues, feature requests, and pull requests are welcome!
Please open a ticket on GitHub: https://github.com/chigwell/forgejo-bot-guard

License

This project is licensed under the MIT License.

Author

Eugene Evstafev
📧 hi@euegne.plus
🐙 GitHub: chigwell

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

forgejo_bot_guard-2025.12.21161612.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

forgejo_bot_guard-2025.12.21161612-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file forgejo_bot_guard-2025.12.21161612.tar.gz.

File metadata

File hashes

Hashes for forgejo_bot_guard-2025.12.21161612.tar.gz
Algorithm Hash digest
SHA256 7651d6edc66f97512519c3508d3f9b336e82a3644f1cbe7c12c190587a5a1955
MD5 33fd0a17aeb5a162b20c8c6db64092dd
BLAKE2b-256 f0d3ad3644682df472b8e8fcccc3933f81917aaa25ff1f231a03af51642e405e

See more details on using hashes here.

File details

Details for the file forgejo_bot_guard-2025.12.21161612-py3-none-any.whl.

File metadata

File hashes

Hashes for forgejo_bot_guard-2025.12.21161612-py3-none-any.whl
Algorithm Hash digest
SHA256 23fa2cd7cd80238d80e47b772589a3550c194992743f003c2cb7880e1816655d
MD5 a27072f4f3d2999b72056194705ab9bf
BLAKE2b-256 fbb941c947cf72de83e9a3344232c357452fc137c2b6a2b2a983d43142f85a12

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