{"data":{"slug":"shroominic-funcchain","name":"funcchain","tagline":"build cognitive systems, pythonic","github_url":"https://github.com/shroominic/funcchain","owner":"shroominic","repo":"funcchain","owner_avatar_url":"https://avatars.githubusercontent.com/u/34897716?v=4","primary_language":"Python","stars":341,"forks":30,"topics":["funcchain","jinja2","langchain","langsmith","llm","minimalistic","openai-functions","prompt","pydantic","python-async","pythonic"],"archived":false,"github_pushed_at":"2024-11-19T09:40:09+00:00","maintenance_label":"Dormant","stars_delta_30d":0,"url":"https://www.graphcanon.com/tools/shroominic-funcchain","markdown_url":"https://www.graphcanon.com/tools/shroominic-funcchain.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/shroominic-funcchain","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=shroominic-funcchain","description":"⛓️ build cognitive systems, pythonic","homepage_url":"https://shroominic.github.io/funcchain/","license":"MIT","open_issues":6,"watchers":11,"ai_summary":"`funcchain` leverages Pydantic models and integrates with LangChain for building cognitive systems that efficiently utilize LLMs.","readme_excerpt":"# funcchain\n\n\n\n\n\n\n\n\n<img alt=\"GitHub Contributors\" src=\"https://img.shields.io/github/contributors/shroominic/funcchain\" />\n<img alt=\"GitHub Last Commit\" src=\"https://img.shields.io/github/last-commit/shroominic/funcchain\" />\n\n\n\n\n```bash\npip install funcchain\n```\n\n## Introduction\n\n`funcchain` is the *most pythonic* way of writing cognitive systems. Leveraging pydantic models as output schemas combined with langchain in the backend allows for a seamless integration of llms into your apps.\nIt utilizes OpenAI Functions or LlamaCpp grammars (json-schema-mode) for efficient structured output.\nIn the backend it compiles the funcchain syntax into langchain runnables so you can easily invoke, stream or batch process your pipelines.\n\n\n\n## Simple Demo\n\n```python\nfrom funcchain import chain\nfrom pydantic import BaseModel\n\n# define your output shape\nclass Recipe(BaseModel):\n    ingredients: list[str]\n    instructions: list[str]\n    duration: int\n\n# write prompts utilising all native python features\ndef generate_recipe(topic: str) -> Recipe:\n    \"\"\"\n    Generate a recipe for a given topic.\n    \"\"\"\n    return chain() # <- this is doing all the magic\n\n# generate llm response\nrecipe = generate_recipe(\"christmas dinner\")\n\n# recipe is automatically converted as pydantic model\nprint(recipe.ingredients)\n```\n\n## Complex Structured Output\n\n```python\nfrom pydantic import BaseModel, Field\nfrom funcchain import chain\n\n# define nested models\nclass Item(BaseModel):\n    name: str = Field(description=\"Name of the item\")\n    description: str = Field(description=\"Description of the item\")\n    keywords: list[str] = Field(description=\"Keywords for the item\")\n\nclass ShoppingList(BaseModel):\n    items: list[Item]\n    store: str = Field(description=\"The store to buy the items from\")\n\nclass TodoList(BaseModel):\n    todos: list[Item]\n    urgency: int = Field(description=\"The urgency of all tasks (1-10)\")\n\n# support for union types\ndef extract_list(user_input: str) -> TodoList | ShoppingList:\n    \"\"\"\n    The user input is either a shopping List or a todo list.\n    \"\"\"\n    return chain()\n\n# the model will choose the output type automatically\nlst = extract_list(\n    input(\"Enter your list: \")\n)\n\n# custom handler based on type\nmatch lst:\n    case ShoppingList(items=items, store=store):\n        print(\"Here is your Shopping List: \")\n        for item in items:\n            print(f\"{item.name}: {item.description}\")\n        print(f\"You need to go to: {store}\")\n\n    case TodoList(todos=todos, urgency=urgency):\n        print(\"Here is your Todo List: \")\n        for item in todos:\n            print(f\"{item.name}: {item.description}\")\n        print(f\"Urgency: {urgency}\")\n```\n\n## Vision Models\n\n```python\nfrom funcchain import Image\nfrom pydantic import BaseModel, Field\nfrom funcchain import chain, settings\n\n# set global llm using model identifiers (see MODELS.md)\nsettings.llm = \"openai/gpt-4-vision-preview\"\n\n# everything defined is part of the prompt\nclass AnalysisResult(BaseModel):\n    \"\"\"The result of an image analysis.\"\"\"\n\n    theme: str = Field(description=\"The theme of the image\")\n    description: str = Field(description=\"A description of the image\")\n    objects: list[str] = Field(description=\"A list of objects found in the image\")\n\n# easy use of images as input with structured output\ndef analyse_image(image: Image) -> AnalysisResult:\n    \"\"\"\n    Analyse the image and extract its\n    theme, description and objects.\n    \"\"\"\n    return chain()\n\nresult = analyse_image(Image.open(\"examples/assets/old_chinese_temple.jpg\"))\n\nprint(\"Theme:\", result.theme)\nprint(\"Description:\", result.description)\nfor obj in result.objects:\n    print(\"Found this object:\", obj)\n```\n\n## Seamless local model support\n\n```python\nfrom pydantic import BaseModel, Field\nfrom funcchain import chain, settings\n\n# auto-download the model from huggingface\nsettings.llm = \"ollama/openchat\"\n\nclass SentimentAnalysis(BaseModel):\n    analysis: str\n    sentiment: bool = Field(description=\"True for Happy, False for Sad\")","github_created_at":"2023-08-31T12:28:34+00:00","created_at":"2026-07-11T10:52:00.748482+00:00","updated_at":"2026-09-20T05:29:43.742727+00:00","categories":[{"slug":"developer-tools","name":"Developer Tools","url":"https://www.graphcanon.com/categories/developer-tools","markdown_url":"https://www.graphcanon.com/categories/developer-tools.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/developer-tools"},{"slug":"llm-frameworks","name":"LLM Frameworks","url":"https://www.graphcanon.com/categories/llm-frameworks","markdown_url":"https://www.graphcanon.com/categories/llm-frameworks.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/llm-frameworks"}],"tags":[{"slug":"langchain","name":"langchain"},{"slug":"openai-functions","name":"openai-functions"},{"slug":"prompt","name":"prompt"},{"slug":"pydantic","name":"pydantic"},{"slug":"python-async","name":"python-async"}],"trust":{"provenance":{"is_fork":false,"github_id":685523400,"owner_type":"User","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-09-20T05:29:40.030Z","maintenance":{"label":"Dormant","score":18,"methodology":"github_public_v1","releases_90d":0,"days_since_push":669,"last_release_at":"2024-11-19T09:40:09Z","stars_delta_30d":0,"open_issues_delta_30d":0},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T10:52:02.107Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-09-20T05:29:41.029Z"},"languages":{"value":["python"],"source":"github.language+pyproject.toml","observed_at":"2026-09-20T05:29:41.029Z"},"license_spdx":{"value":"MIT","source":"github.license","observed_at":"2026-09-20T05:29:41.029Z"}},"decision_facts":{"hosting":null,"pricing":{"model":"freemium","summary":"`funcchain` itself is free under MIT license, but dependencies like LangChain and OpenAI may incur costs based on their usage and respective plans."},"requirements":{"notes":["`funcchain` requires Python and its dependencies, including Pydantic, LangChain, Jinja2, OpenAI, and others."],"min_ram_gb":2,"requires_docker":false},"constraints":{"min_ram_gb":2,"pricing_model":"freemium","requires_docker":false},"when_to_use":["When you need a seamless integration of Pydantic models and LangChain into your cognitive systems to ensure type safety and structured data handling.","For projects where the output needs to be efficiently converted into Pydantic models with complex nested structures, providing strong typing and validation.","If your application requires support for union types (e.g., determining if input is a todo list or shopping list) where automatic model selection benefits the project."],"when_not_to_use":["When you prefer frameworks that do not rely on Pydantic models, as this tool strictly enforces their use for data modeling.","If you are working in a language other than Python, as `funcchain` is specifically designed for Python applications and lacks cross-language support.","For projects where minimalistic design is less preferred compared to more verbose or modular configurations that allow greater customization outside the constraints of predefined Pydantic models."],"source":"enrich:decision_facts","observed_at":"2026-07-12T16:58:17.956Z"},"constraint_facets":{"min_ram_gb":2,"pricing_model":"freemium","requires_docker":false},"decision_summary":[{"label":"Pricing","value":"freemium - `funcchain` itself is free under MIT license, but dependencies like LangChain and OpenAI may incur costs based on their usage and respective plans."},{"label":"Requirements","value":"Min 2 GB RAM; `funcchain` requires Python and its dependencies, including Pydantic, LangChain, Jinja2, OpenAI, and others."},{"label":"Adopt for","value":"`funcchain` integrates Pydantic models with LangChain to build cognitive systems in a Pythonic way, leveraging LLMs for efficient structured output."}]}}