Skip to main content

groq-chain

PyPI MIT License GitHub Python

Dead-simple Groq LLM chaining in Python. Chain prompts with .step() — no LangChain needed.

LangChain is overkill for most things. groq-chain gives you prompt chaining in plain Python — pass the output of one LLM call into the next, with zero magic.

groq-chain demo

When to use this

Use groq-chain when:

  • You need to chain 2–5 LLM calls where each step feeds the next (summarize → rewrite → translate)
  • You want Groq's speed without the LangChain abstraction overhead
  • You're building document pipelines, content transforms, or multi-step AI workflows in pure Python
  • You want something you can read and understand in 10 minutes

Not the right fit if you need agents, tool calling, vector stores, or retrieval — LangChain or LlamaIndex are built for that. groq-chain is intentionally a thin wrapper for linear prompt pipelines.


Why not LangChain?

groq-chain LangChain
Install size 1 dependency (groq) 50+ transitive dependencies
Lines to chain 3 prompts ~5 ~40
Learning curve Read the README once Days
Best for Linear pipelines Agents, RAG, complex graphs

If you're chaining prompts, not building an agent, groq-chain does it in a fraction of the code.


Install

pip install groq-chain

Note: the package is groq-chain but the import is groqchain (no hyphen):

from groqchain import GroqChain

Or from source:

git clone https://github.com/iamadhitya1/groq-chain
pip install -e groq-chain/

Quick start

from groqchain import GroqChain

chain = GroqChain(api_key="gsk_...")  # or set GROQ_API_KEY env var

# Single call
result = chain.run("Summarize this in 3 bullet points: {text}", text="...")
print(result)

Chained calls

Pass the output of each step into the next automatically:

result = (
    GroqChain(api_key="gsk_...")
    .step("Extract 3 key insights from: {text}", output_key="insights", text="...")
    .step("Write a LinkedIn post based on these insights: {insights}")
    .run()
)
print(result)

Each .step() receives the previous step's output via output_key.


Get all step outputs

results = (
    GroqChain(api_key="gsk_...")
    .step("Translate to French: {text}", output_key="french", text="Hello world")
    .step("Now translate the French to Spanish: {french}", output_key="spanish")
    .run_all()
)

print(results["french"])   # Bonjour le monde
print(results["spanish"])  # Hola mundo

Inject context

chain = (
    GroqChain(api_key="gsk_...")
    .context(language="Hindi", tone="casual")
    .step("Write a {tone} greeting in {language}")
)
result = chain.run()

System prompt

chain = GroqChain(
    api_key="gsk_...",
    system="You are a senior software engineer. Be concise and technical.",
)
result = chain.run("Review this code: {code}", code="...")

All options

GroqChain(
    api_key="gsk_...",                      # or GROQ_API_KEY env var
    model="llama-3.3-70b-versatile",        # any Groq model
    temperature=0.7,
    max_tokens=1024,
    system="Optional system prompt",
)

Available Groq models:

  • llama-3.3-70b-versatile ← default
  • llama-3.1-8b-instant
  • mixtral-8x7b-32768
  • gemma2-9b-it

Real-world example — document pipeline

import os
from groqchain import GroqChain

chain = GroqChain(api_key=os.environ["GROQ_API_KEY"])

with open("contract.txt") as f:
    doc = f.read()

results = (
    chain
    .step("Summarize this legal document: {doc}", output_key="summary", doc=doc)
    .step("List any risky clauses from this summary: {summary}", output_key="risks")
    .step("Rate the overall risk from 1-10 and explain why: {risks}", output_key="rating")
    .run_all()
)

print("Summary:", results["summary"])
print("Risks:",   results["risks"])
print("Rating:",  results["rating"])

Author

M. Adhitya — Founder, Rewrite Labs

License

MIT © 2025 M. Adhitya

Built at Rewrite Labs

Metadata

Release files for groq-chain 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for groq-chain 1.0.2
File Size Uploaded Provenance Actions
groq_chain-1.0.2.tar.gz 6.4 kB Without provenance Details for groq_chain-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for groq-chain 1.0.2
File Interpreter ABI Platform Actions
groq_chain-1.0.2-py3-none-any.whl Python 3 none any Details for groq_chain-1.0.2-py3-none-any.whl

Total release size: 13.0 kB

Release files / groq_chain-1.0.2.tar.gz

Download URL groq_chain-1.0.2.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dc74602aba6051f9360b2a3c8ee8ce34e6327dd54a49c54c574487af9bbcc6a9
BLAKE2b-256 checksum
How to use checksums
cd8d8a9ebc620270daccaa6e6b9bdaee631e20707a205fcdab1eb5ebff9d732a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / groq_chain-1.0.2-py3-none-any.whl

Download URL groq_chain-1.0.2-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
124bb2848d898521bdfd62c6fde8c136b1c545d1d5a089d9899e85b5077ec827
BLAKE2b-256 checksum
How to use checksums
4f79ee9908b2b88b676e1ff055b096bf50621e66064aabfd31fea34d64421e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for groq-chain 1.0.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page