Skip to main content

personasurvey

Run reproducible persona surveys from a Pandas DataFrame. The public workflow is deliberately small:

run_simulation(...)
continue_simulation(...)

There is no await in notebook or script code. The package manages its asynchronous requests internally.

Install

Install the published package:

pip install personasurvey

Install test dependencies too:

pip install "personasurvey[dev]"

Load an example dataset

The repository includes 100 fictional personas with demographic columns and one individual English description per person. Load it directly:

import pandas as pd

DATASET_URL = "https://raw.githubusercontent.com/Japulgarin/personasurvey/main/examples/fictional_personas_100.csv"
df = pd.read_csv(DATASET_URL)

print(df.iloc[0])

Example row:

persona_id                                                        P001
name                                                    Avery Morgan
age                                                                 25
region                                                           North
occupation                                                    Teacher
community_priority                                             jobs
persona_description  Avery Morgan is a fictional teacher in Riverton...

Define a prompt and see the exact input

from personasurvey import PersonaPrompt, ResponseSchema

schema = ResponseSchema.probabilities(["Candidate A", "Candidate B"])

prompt = PersonaPrompt(
    demographic_cols=["age", "region", "city", "education", "occupation", "community_priority"],
    persona_detail_cols=["persona_description", "hobby"],
    scenario="""Fictional candidate propositions:
- Candidate A: expand local health clinics and fund apprenticeships.
- Candidate B: lower prescription costs and expand tenant protections.

How would this person divide support between Candidate A and Candidate B?""",
    response_schema=schema,
)

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

Run and inspect input/output

Use a local LM Studio server, RunPod, OpenRouter, OpenAI, Gemini, or Anthropic provider. This example runs a small local LM Studio job:

from personasurvey import OpenAIProvider, run_simulation

provider = OpenAIProvider(
    base_url="http://127.0.0.1:1234/v1",
    model="google/gemma-4-e2b",
    api_key="lm-studio",
    structured_output=True,
)

run = run_simulation(
    df=df,
    prompt=prompt,
    provider=provider,
    id_col="persona_id",
    checkpoint="example_run.jsonl",
    n=10,
    concurrency=1,
    max_tokens=300,
    temperature=0,
)

row = run.results.iloc[0]
print("INPUT SENT TO THE MODEL:\n", row["input"])
print("\nRAW MODEL OUTPUT:\n", row["output"])
print("\nPARSED RESPONSE:")
print(row[["Candidate A", "Candidate B", "reason", "in_tok", "out_tok"]])

run.results always includes:

  • input: the complete prompt sent for that row.
  • output: the raw model response.
  • parsed fields such as Candidate A, Candidate B, and reason when a schema is used.
  • in_tok, out_tok, endpoint, provider, status, and error.

If a model stops before completing JSON, the row is saved as an error and error explains whether it likely reached max_tokens. Increase max_tokens and use continue_simulation(...); successful rows are not sent again.

Concurrency

concurrency is optional and belongs to run_simulation or continue_simulation, not to RunPodProvider.

# Let the package choose its internal default.
run = run_simulation(...)

# Limit a real test to three simultaneous requests per endpoint.
run = run_simulation(..., concurrency=3)

With one endpoint, concurrency=3 means up to three simultaneous requests. With two RunPod endpoints, each endpoint receives an even fixed half of the pending rows and can process up to three simultaneous requests (up to six total).

For a large RunPod experiment, begin with concurrency=100, confirm the pod is stable, then increase gradually to 300, 500, or 1000. The requested value now also sets the HTTP connection-pool capacity, so concurrency=1000 can keep 1,000 requests in flight per real endpoint. Use that value only when your vLLM pod can sustain it; otherwise requests will queue or time out.

large_run = continue_simulation(
    df=df, prompt=prompt, provider=runpod, id_col="persona_id",
    checkpoint="country_trial_01.jsonl", n=200_000,
    concurrency=1000, max_tokens=800, temperature=0,
    retries=3, timeout=180, stall_timeout=300,
)

Continue safely

Stop the notebook, change provider settings, or add endpoints. Continue with the same JSONL file and successful IDs will not be sent again:

from personasurvey import continue_simulation

results = continue_simulation(
    df=df,
    prompt=prompt,
    provider=provider,
    id_col="persona_id",
    checkpoint="example_run.jsonl",
)

Providers

The prompt, DataFrame, schema, checkpoint, result columns, and run_simulation call stay the same.

from personasurvey import (
    AnthropicProvider, GeminiProvider, OpenAIProvider,
    OpenRouterProvider, RunPodProvider,
)

# LM Studio or any local OpenAI-compatible server.
provider = OpenAIProvider(
    base_url="http://127.0.0.1:1234/v1",
    model="google/gemma-4-e2b",
    api_key="lm-studio",
    structured_output=True,
)

# One or more RunPod/vLLM endpoints. Pending work is split evenly between them.
provider = RunPodProvider(
    urls=["https://your-pod-1.proxy.runpod.net/", "https://your-pod-2.proxy.runpod.net/"],
    model="openai/gpt-oss-20b",
)

# OpenRouter reads OPENROUTER_API_KEY from the environment.
provider = OpenRouterProvider(model="openai/gpt-oss-20b")

# Official OpenAI reads OPENAI_API_KEY from the environment.
provider = OpenAIProvider(model="gpt-4.1-mini")

# Gemini: pip install "personasurvey[gemini]"; reads GEMINI_API_KEY.
provider = GeminiProvider(model="gemini-2.5-flash")

# Anthropic: pip install "personasurvey[anthropic]"; reads ANTHROPIC_API_KEY.
provider = AnthropicProvider(model="claude-sonnet-4-5")

Change provider and continue the same checkpoint

This is the usual recovery or scale-up workflow. Start with a small local run, then change only provider and call continue_simulation with the identical checkpoint path. Successful IDs are skipped; failures and pending IDs are retried.

# First: ten local requests.
local = OpenAIProvider(
    base_url="http://127.0.0.1:1234/v1",
    model="google/gemma-4-e2b",
    api_key="lm-studio",
    structured_output=True,
)
first = run_simulation(
    df=df, prompt=prompt, provider=local, id_col="persona_id",
    checkpoint="country_trial_01.jsonl", n=10, concurrency=1,
    max_tokens=600, temperature=0,
)

# Later: continue the same rows with two RunPod workers.
runpod = RunPodProvider(
    urls=["https://your-pod-1.proxy.runpod.net/", "https://your-pod-2.proxy.runpod.net/"],
    model="openai/gpt-oss-20b",
)
final = continue_simulation(
    df=df, prompt=prompt, provider=runpod, id_col="persona_id",
    checkpoint="country_trial_01.jsonl", n=200_000, concurrency=3,
    max_tokens=800, temperature=0, json_mode=True,
)

print(final.results[["_id", "provider", "endpoint", "status", "input", "output"]].head())

Credentials are supplied as provider arguments or environment variables. Do not put API keys in notebooks, source files, checkpoints, or GitHub.

Included examples

  • examples/fictional_personas_100.csv: loadable fictional input dataset.
  • examples/fictional_results_100.json: completed example results.
  • examples/walkthrough.ipynb: a step-by-step notebook.

Metadata

Release files for personasurvey 0.2.3

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.3
File Size Uploaded Provenance Actions
personasurvey-0.2.3.tar.gz 20.1 kB Without provenance Details for personasurvey-0.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 38.2 kB

Release files / personasurvey-0.2.3.tar.gz

Download URL personasurvey-0.2.3.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
26c372c81130f7a6b31d93072ee848847c0a8492e60c3780e11ae3538710fdfd
BLAKE2b-256 checksum
How to use checksums
2c500ce7b4685bbc6ed1c5ba5445505b283950bcc420bdb7fb10539e6c5664a8
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.3-py3-none-any.whl

Download URL personasurvey-0.2.3-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd6450bb4c0ba820f847bcf9e3b884a5e939a7c47f7c7da59acb30d08cc87450
BLAKE2b-256 checksum
How to use checksums
61b5fe9e3235530aae96236f36fa6369130141b5c38b598334555cefcd279a2b
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.3

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