Skip to main content

synloc: An Algorithm to Create Synthetic Tabular Data

synloc

Overview | Data Requirements | Installation | A Quick Example | Documentation | How to cite? | Replication

PyPI Python Downloads

Overview

synloc is an open-source Python package implementing the Local Resampler (LR) algorithm for generating synthetic tabular data while safeguarding privacy. It provides a computationally efficient and flexible approach to synthetic data generation, enabling researchers to work with privacy-preserving datasets that maintain statistical utility.

Two Subsampling Strategies

Both approaches provide effective disclosure control. Choose based on your priorities:

Approach Best for Key advantage
k-Nearest Neighbors (k-NN) Stronger disclosure control Naturally underrepresents outliers, reducing privacy risks
Clustering-based Efficiency & accuracy Better data utility and computational performance

Key features:

  • Natural disclosure risk reduction by underrepresenting outliers (k-NN variant)
  • Accurate replication of complex distributions, including multimodal and non-convex-support data
  • Flexible trade-off between data utility and privacy protection
  • Built-in quality diagnostics, including Kolmogorov-Smirnov distances, Wasserstein distances, summary statistics, and correlation-difference metrics
  • Compatible with parametric and nonparametric distributions

This implementation aligns with statistical agencies' safe data regulations, including the k-anonymity criterion and the Five Safes framework adopted by organizations such as the Australian Bureau of Statistics. For the full methodology and theoretical foundations, see the paper referenced below.

Data Requirements

synloc expects a numeric pandas.DataFrame.

  • Categorical variables must be encoded before synthesis, for example with pandas.get_dummies.
  • Boolean dummy variables are accepted and converted to 0/1.
  • Missing numeric values are filled with column medians during fitting.
  • Columns with only missing values, duplicate column names, infinite values, and non-numeric columns raise clear errors.
  • Integer-like variables can be rounded after synthesis with round_integers.

Installation

synloc can be installed through PyPI:

pip install synloc

A Quick Example

Assume that we have a sample with three variables with the following distributions:

$$x \sim Beta(0.1,,0.1)$$

$$y \sim Beta(0.1,, 0.5)$$

$$z \sim 10 y + Normal(0,,1)$$

The distribution can be generated by tools module in synloc:

from synloc.tools import sample_trivariate_xyz
data = sample_trivariate_xyz() # Generates a sample with size 1000 by default. 

Initializing the resampler:

from synloc import LocalCov
resampler = LocalCov(data = data, K = 30)

Subsample size is defined as K=30. Now, we locally estimate the multivariate normal distribution and from each estimated distributions we draw "synthetic values."

syn_data = resampler.fit() 

syn_data is a pandas.DataFrame where all variables are synthesized. Comparing the original sample using a 3-D Scatter:

resampler.comparePlots(['x','y','z'])

You can also inspect utility diagnostics after fitting:

variable_metrics = resampler.compareStats()
quality = resampler.qualityReport()

print(variable_metrics[["ks_statistic", "wasserstein_distance"]])
print(quality["overall"])

Model export

synloc 1.1 can export a fitted clusterCov or LocalCov model and generate synthetic data elsewhere without the original records. See the model export guide.

How to cite?

If you use synloc in your research, please cite the following paper:

@article{https://doi.org/10.1111/anzs.70032,
    author = {Kalay, Ali Furkan},
    title = {Generating Synthetic Data With Locally Estimated Distributions for Disclosure Control},
    journal = {Australian \& New Zealand Journal of Statistics},
    volume = {68},
    number = {1},
    pages = {e70032},
    doi = {https://doi.org/10.1111/anzs.70032},
    url = {https://onlinelibrary.wiley.com/doi/abs/10.1111/anzs.70032},
    eprint = {https://onlinelibrary.wiley.com/doi/pdf/10.1111/anzs.70032},
    year = {2026}
}

Replication

For replication materials of the paper, see the replication folder.

Metadata

Release files for synloc 1.1.0

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

Source distribution (sdist)

Source distribution for synloc 1.1.0
File Size Uploaded Provenance Actions
synloc-1.1.0.tar.gz 29.4 kB Without provenance Details for synloc-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 51.1 kB

Release files / synloc-1.1.0.tar.gz

Download URL synloc-1.1.0.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bae56366f654a4c0cf014ce54d7a38cd82ba2395cd039f6ba1d5527266ad415b
BLAKE2b-256 checksum
How to use checksums
dbcbcd000de37895088c4a15d1ac356f788a275306625580caf6036cf43242b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / synloc-1.1.0-py3-none-any.whl

Download URL synloc-1.1.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfa3f9a624df0ae9b2b22200710a2563095dcbccb343256c162cd3a7e37a105c
BLAKE2b-256 checksum
How to use checksums
26ea3248f55101850213c92e15f20b23357fe546120e6d18d44dfcd5c7b08839
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for synloc 1.1.0

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