Pre-release
This release is a pre-release and may not be stable for production use.
Pulsar: Structured LLM Output Parser
Pulsar is the today and next-generation tool to build AI applicatios by providing structured output parsing. It allow use with any model hosted in an API compatible with OpenAIAPI, even if that doesn't support json, or function calling (OpenAI o1, Qwen QwQ, DeepSeek R1 ..) and models multi-modal.
Installation
pip install pulsar-struct
Quick Start
from pulsar.client import Client
from pydantic import BaseModel
# Define your output structure
class UserInfo(BaseModel):
name: str
age: int
interests: List[str]
# Initialize client
client = Client()
# Get structured response
response, metadata = client.chat_completion(
messages=[{"role": "user", "content": "Extract: John, 25 years old, likes reading and hiking"}],
model="openai/gpt-4o-mini",
response_type=UserInfo
)
print(response) # UserInfo(name='John', age=25, interests=['reading', 'hiking'])
Provider Configuration
Current supported providers:
- OpenAI
- Anthropic
- Gemini
- Groq
- OpenRouter
- Ollama
- OpenAIAPILike
Each provider can be configured with specific options:
# Anthropic
client = AnthropicClient(api_key="your-anthropic-key")
# OpenAI
client = OpenAIClient(api_key="your-openai-key")
# Groq
client = GroqClient(api_key="your-groq-key")
# Ollama
client = OllamaClient() # or set the enpoint using base_url="http://host:port"
# default is "http://localhost:11434"
Advanced Usage
Structured output parsing handle all in background for you:
- Convert LLM responses to Pydantic models
- Automatic type coercion
- Handle imperfect JSON responses
- Support for complex data types (enums, literals, nested models)
Custom Response Types
from typing import List, Optional
from pydantic import BaseModel
from enum import Enum
class Sentiment(Enum):
POSITIVE = "positive"
NEGATIVE = "negative"
NEUTRAL = "neutral"
class Analysis(BaseModel):
sentiment: Sentiment
confidence: float
keywords: List[str]
summary: Optional[str]
response, metadata = client.chat_completion(
system="Analyse the products",
messages=[{"role": "user", "content": "Analyze: Great product, highly recommend!"}],
model="claude-2",
response_type=Analysis
)
Endpoint Retries
response, _ = client.chat_completion(
messages=[...],
model="gpt-4",
max_retries=3
)
Streaming Support
client = Client()
for chunk, _ in client.chat_completion(
messages=[...],
model="groq/llama-3.3-70b-versatile",
stream=True
):
print(chunk, end="")
JSON Parsing Features
- Handle unquoted strings
- Fix missing commas and brackets
- Support for partial objects (streaming)
- Automatic type coercion
- Handle embedded type information
Release files for pulsar-struct 0.2.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pulsar_struct-0.2.0.dev0.tar.gz | 52.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pulsar_struct-0.2.0.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:101.8 kB
Release files / pulsar_struct-0.2.0.dev0.tar.gz
| Download URL | pulsar_struct-0.2.0.dev0.tar.gz |
|---|---|
| Size | 52.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc97dc82f43d75282c2ad421e1c3b64145b7945db4b620f32333fd4aa313b76f
|
|
BLAKE2b-256 checksum How to use checksums |
a045e1bae363a3b008cf253371a62e82439c91e966fb41d5826332d3147d7cfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Release files / pulsar_struct-0.2.0.dev0-py3-none-any.whl
| Download URL | pulsar_struct-0.2.0.dev0-py3-none-any.whl |
|---|---|
| Size | 49.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f2b20692c7c2829758cef7c3adf51c4b217f33b14d744eccc534eaeff191e4b
|
|
BLAKE2b-256 checksum How to use checksums |
176bc1cc53a6711537193cf08de3a2094acd30a221d6004efdf6738c7dc892aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|