Skip to main content

text-to-struct

PyPI version License: MIT Downloads LinkedIn

A Python package that transforms unstructured text inputs into structured, standardized outputs using LLM7 and llmatch-messages.

Overview

text_to_struct enables users to process textual descriptions, ideas, or concepts, and generate structured data adhering to a predefined format. It leverages the LLM7 language model via the langchain_llm7 package, combined with llmatch-messages to ensure the output matches specified patterns. This approach promotes consistency and ease of parsing, making the package particularly useful for content creation, brainstorming, and idea management systems.

Installation

pip install text_to_struct

Usage

from text_to_struct import text_to_struct

# Example usage with default LLM7
response = text_to_struct(user_input="Describe a new innovative app idea.")
print(response)

Parameters

  • user_input (str): The unstructured text to be processed.
  • llm (Optional[BaseChatModel]): An optional langchain LLM instance. If not provided, the default ChatLLM7 will be used.
  • api_key (Optional[str]): The API key for LLM7. If not provided, it will be fetched from the LLM7_API_KEY environment variable.

Available LLMs

You can pass your own LLM instances from various providers, such as:

Using langchain's OpenAI

from langchain_openai import ChatOpenAI
from text_to_struct import text_to_struct

llm = ChatOpenAI()
response = text_to_struct(user_input, llm=llm)

Using langchain's Anthropic

from langchain_anthropic import ChatAnthropic
from text_to_struct import text_to_struct

llm = ChatAnthropic()
response = text_to_struct(user_input, llm=llm)

Using langchain's Google Generative AI

from langchain_google_genai import ChatGoogleGenerativeAI
from text_to_struct import text_to_struct

llm = ChatGoogleGenerativeAI()
response = text_to_struct(user_input, llm=llm)

API Key & Rate Limits

The default free-tier rate limits for LLM7 are sufficient for most use cases. To access higher rate limits, set your API key via:

  • Environment variable: LLM7_API_KEY
  • Or pass directly: text_to_struct(user_input, api_key="your_api_key")

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

Development & Support

Source Code

The core functionality is built on the langchain_llm7 package (available on PyPI), which interfaces with LLM7. The package also uses llmatch_messages for pattern matching and ensuring output structure.


Note: The text_to_struct function relies on a pattern matching regex and specific prompts (system_prompt and human_prompt) to guide the LLM output. Make sure your input and patterns align with your expected structured output.

Release files for text-to-struct 2025.12.22084055

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

Source distribution (sdist)

Source distribution for text-to-struct 2025.12.22084055
File Size Uploaded
text_to_struct-2025.12.22084055.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for text-to-struct 2025.12.22084055
File Interpreter ABI Platform
text_to_struct-2025.12.22084055-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / text_to_struct-2025.12.22084055.tar.gz

Download URL text_to_struct-2025.12.22084055.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cf10a604b9da22c745398fbc1febb9ebee852c9a2b1492b583544a8f8e7b8db8
BLAKE2b-256 checksum
How to use checksums
087a9066a79ab5d3b12a9ffc86d80d8ac89815ac58c032239d986b2c892ecef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Release files / text_to_struct-2025.12.22084055-py3-none-any.whl

Download URL text_to_struct-2025.12.22084055-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b16c40224dd4e91957dc936ad617de7d29e5911ff9fb9b40e673ece6bb72e929
BLAKE2b-256 checksum
How to use checksums
193fa5283af616afb44a41d3c5d56a1f91cca2d4f5542a635fcf4a1bd5c6b8a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

2025.12.22084055 This release

2 release files

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