Skip to main content

personasurvey

Run persona surveys from a Pandas DataFrame. It creates prompts, sends async requests, saves JSONL checkpoints, resumes safely, and compares prompt experiments.

Install

pip install personasurvey
pip install "personasurvey[analytics]"

1. Load people

import pandas as pd

df = pd.read_csv("people.csv")
df["row_id"] = range(1, len(df) + 1)
df.head()

2. Create a prompt

from personasurvey import PersonaPrompt, ResponseSchema

prompt = PersonaPrompt(
    name="usa_persona",
    demographic_cols=["state", "city", "age", "education_level", "occupation"],
    persona_detail_cols=["persona"],
    scenario="""Candidate A supports local health clinics.
Candidate B supports lower prescription prices.
How would this person divide support?""",
    response_schema=ResponseSchema.probabilities(["Candidate A", "Candidate B"]),
)

prompt.validate(df)
print(prompt.preview(df.iloc[0]))

For a vLLM prefix-cache experiment, create the same prompt with persona_at_end=True. All person-specific fields (DEMOGRAPHICS and PERSONA DETAILS) move after the static context and JSON instructions.

3. Choose a provider

from personasurvey import RunPodProvider

provider = RunPodProvider(
    urls=[
        "https://your-pod-1.proxy.runpod.net/",
        "https://your-pod-2.proxy.runpod.net/",
    ],
    model="openai/gpt-oss-20b",
    api_key="EMPTY",
)
from personasurvey import OpenAIProvider, OpenRouterProvider, GeminiProvider, AnthropicProvider

local = OpenAIProvider(base_url="http://127.0.0.1:1234/v1", model="google/gemma-4-e2b", api_key="lm-studio")
openrouter = OpenRouterProvider(model="openai/gpt-oss-20b")
openai = OpenAIProvider(model="gpt-4.1-mini")
gemini = GeminiProvider(model="gemini-2.5-flash")
claude = AnthropicProvider(model="claude-sonnet-4-5")

4. Run

from personasurvey import run_simulation

run = run_simulation(
    df=df,
    prompt=prompt,
    provider=provider,
    id_col="row_id",
    checkpoint="usa_persona.jsonl",
    n=5_000,
    concurrency=800,
    max_tokens=800,
    temperature=0,
    json_mode=True,
    retries=3,
    timeout=180,
    stall_timeout=60,
)

print(run.summary)
display(run.results.head())

concurrency=800 with two endpoints means 400 in-flight requests per pod. Work is split evenly: 5,000 people becomes 2,500 per pod.

5. Read one result

row = run.results.iloc[0]

print(row["input"])
print(row["output"])
print(row[["Candidate A", "Candidate B", "reason", "status", "in_tok", "out_tok"]])

run.results contains model data. run.merged contains the original person columns plus model data.

6. Continue

from personasurvey import continue_simulation

run = continue_simulation(
    df=df,
    prompt=prompt,
    provider=provider,
    id_col="row_id",
    checkpoint="usa_persona.jsonl",
)

Successful IDs are skipped. Errors and pending rows are retried.

Compare prompts

from personasurvey import compare

comparison = compare(
    df,
    id_col="row_id",
    cultural="usa_cultural.jsonl",
    persona="usa_persona.jsonl",
)

display(comparison.data.head())
display(comparison.summary())
display(comparison.by("education_level"))
display(comparison.flips())
display(comparison.change_of_mind(n=10))

compare() detects numeric candidate fields, joins original population columns, creates winner columns, and never sends a model request.

comparison.sql("""
    SELECT state,
           COUNT(*) AS people,
           AVG("Candidate A__persona" - "Candidate A__cultural") AS prompt_effect
    FROM comparison
    GROUP BY state
    ORDER BY prompt_effect DESC
""")

Functions

Function Use
PersonaPrompt(...) Define columns, scenario, and JSON response.
prompt.preview(row) Print one exact prompt before running.
run_simulation(...) Start a checkpointed experiment.
continue_simulation(...) Resume the same JSONL checkpoint.
compare(df, cultural=..., persona=...) Compare existing prompt experiments.
comparison.by("state") Results by any population column.
comparison.flips() People whose predicted winner changed.
comparison.change_of_mind() Person, probabilities, and both model reasons.
comparison.sql(...) Fast DuckDB query over the comparison.

Examples: examples/walkthrough.ipynb and examples/fictional_personas_100.csv.

Metadata

Release files for personasurvey 0.2.6

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

Source distribution (sdist)

Source distribution for personasurvey 0.2.6
File Size Uploaded Provenance Actions
personasurvey-0.2.6.tar.gz 24.5 kB Without provenance Details for personasurvey-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for personasurvey 0.2.6
File Interpreter ABI Platform Actions
personasurvey-0.2.6-py3-none-any.whl Python 3 none any Details for personasurvey-0.2.6-py3-none-any.whl

Total release size: 46.7 kB

Release files / personasurvey-0.2.6.tar.gz

Download URL personasurvey-0.2.6.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4eb9d4b4a7f880229fec96fa6b60122b6abd91c2a5fdc01f31091873174296d7
BLAKE2b-256 checksum
How to use checksums
17373b15fd051ad73a0d0f1fbc3df58f8562105cd620672ff72e6b8cc59b4c5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / personasurvey-0.2.6-py3-none-any.whl

Download URL personasurvey-0.2.6-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc3864fe934cab917d27ad50e88c02cd189bc2538c754e8e04521449c7f4b868
BLAKE2b-256 checksum
How to use checksums
6c2d9d8fce23755204ce84bd7cd6c9b35d134efbadc1623f5866fa330e86a16b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for personasurvey 0.2.6

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