Install svy and learn how its core objects fit together
Getting Started
Installation
Tutorial
Python
Install svy and learn its object model: describe a survey Design, wrap your data in a Sample, then run design-based estimation and regression through simple accessors.
Author
Mamadou S. Diallo, Ph.D.
Published
January 18, 2026
Modified
July 21, 2026
Keywords
install svy Python, svy getting started, svy Python tutorial, svy Design and Sample objects, design-based inference Python, survey weighting and estimation Python, stratified cluster sampling Python, Python survey analysis library, R survey package Python alternative
This page gets svy installed and gives you a mental model of the library: a small set of objects that compose the same way for every task. Once the model clicks, the tutorials are just deeper dives into each piece.
For virtual-environment setup, uv projects, and troubleshooting, see the full Installation guide.
The svy Object Model
svy has a small, composable object model. Nearly every workflow follows the same three moves:
Describe the design with svy.Design(...) — how the sample was drawn.
Bind data and design into a svy.Sample(...) — the hub for everything.
Analyze through an accessor — sample.<accessor>.<method>().
import svy# A small example survey bundled with svy (runs offline)data = svy.datasets.load("hld_sample_wb_2023", source="bundled")# 1. Describe the sampling designdesign = svy.Design( stratum=("geo1", "urbrur"), # stratification psu="ea", # primary sampling units (clusters) wgt="hhweight", # survey weights)# 2. Bind data + designsample = svy.Sample(data=data, design=design)print(sample)
╭────────────── Sample ───────────────╮│Survey Data││ Rows : 825 ││ Columns : 19 ││ Strata : 7 ││ PSUs : 33 ││││Survey Design││ Row index svy_row_index ││ Stratum (geo1, urbrur) ││ PSU ea ││ SSU None ││ Weight hhweight ││ With replacement False ││ Prob None ││ Hit None ││ MOS None ││ Population size None ││ Replicate weights None │╰─────────────────────────────────────╯
Design accepts the pieces of any probability design — stratum, psu, ssu (second stage), wgt, fpc, and rep_weights for replicate-weight methods. Pass only what your design uses.
Everything hangs off the Sample
Once you have a sample i.e. sample=svy.Sample(...), each kind of task lives on its own accessor, so the call always reads sample.<accessor>.<method>():
For example, a design-based mean is sample.estimation.mean("pc_exp"), and a regression is sample.glm.fit(...) — see the Quick Start for both running end to end.
Planning a survey before you have data?
Sample-size and power calculations have their own entry point, svy.SampleSize(...) — see Planning.
Reading your own files uses svy.io (and the svy-io package for SPSS/Stata/SAS); the bundled example datasets above come from svy.datasets — see Datasets.
Ready to Explore?
Continue with hands-on tutorials covering real survey analysis workflows.