fejkdata 0.9.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fejkdata/__init__.py ADDED
@@ -0,0 +1,89 @@
1
+ """Fake data for tests, rendered by the fejkdata CLI binary this package carries."""
2
+
3
+ import datetime
4
+ import os
5
+ import pathlib
6
+ import subprocess
7
+ from collections.abc import Iterable
8
+
9
+ __all__ = ["FejkdataError", "paths", "render"]
10
+
11
+ # The last line of some CLI errors, which helps only at a shell: cli/report.go's advice lines,
12
+ # which testdata/shell_advice.json pins for both.
13
+ _SHELL_ADVICE = (
14
+ "try 'fejkdata --help'",
15
+ "wrap that JSON in single quotes, which keep a shell from expanding its braces",
16
+ )
17
+ _Folders = str | os.PathLike[str] | Iterable[str | os.PathLike[str]] | None
18
+ _BINARY = pathlib.Path(__file__).parent / "bin" / ("fejkdata.exe" if os.name == "nt" else "fejkdata")
19
+
20
+
21
+ class FejkdataError(Exception):
22
+ """A call the CLI refused, a render or a listing. The message is the CLI's error text, and returncode the CLI's exit code."""
23
+
24
+ def __init__(self, message: str, returncode: int) -> None:
25
+ super().__init__(message)
26
+ self.returncode = returncode
27
+
28
+
29
+ def render(
30
+ template: str,
31
+ *,
32
+ seed: int,
33
+ today: datetime.date | str,
34
+ repeat: int = 1,
35
+ format: str = "text",
36
+ table: str | None = None,
37
+ data_path: _Folders = None,
38
+ no_shipped_data: bool = False,
39
+ separator: str | None = None,
40
+ null_text: str | None = None,
41
+ ) -> str:
42
+ """Renders template as `fejkdata --seed … --today … --repeat … --format …` does, and returns what it prints.
43
+
44
+ today is a date, or a string such as 2026-01-15. table, data_path, separator and null_text pass the CLI flag of their name
45
+ unless they are None, and no_shipped_data passes its flag when True. data_path takes a folder or several, the last winning
46
+ on a clash. A render the CLI refuses raises FejkdataError.
47
+ """
48
+ day = today if isinstance(today, str) else today.strftime("%Y-%m-%d")
49
+ flags = _data_flags(data_path, no_shipped_data)
50
+ for flag, value in (("table", table), ("separator", separator), ("null-text", null_text)):
51
+ if value is not None:
52
+ flags.append(f"--{flag}={value}")
53
+ return _run(["--seed", str(seed), "--today", day, "--repeat", str(repeat), "--format", format, *flags], template)
54
+
55
+
56
+ def paths(
57
+ *,
58
+ data_path: _Folders = None,
59
+ no_shipped_data: bool = False,
60
+ ) -> list[str]:
61
+ """Lists every path the data offers, in the order `fejkdata --list` prints them.
62
+
63
+ data_path and no_shipped_data mean what they do for render. A path has no leading slash, which a reference in a template
64
+ adds: "sv_SE.person" is written {/sv_SE.person}. A folder the CLI refuses raises FejkdataError.
65
+ """
66
+ return _run(["--list", *_data_flags(data_path, no_shipped_data)], "").split("\n")[:-1]
67
+
68
+
69
+ def _data_flags(data_path: _Folders, no_shipped_data: bool) -> list[str]:
70
+ folders = [data_path] if isinstance(data_path, (str, os.PathLike)) else data_path or ()
71
+ flags = [f"--data-path={os.fspath(folder)}" for folder in folders]
72
+ if no_shipped_data:
73
+ flags.append("--no-shipped-data")
74
+ return flags
75
+
76
+
77
+ def _run(arguments: list[str], template: str) -> str:
78
+ done = subprocess.run(
79
+ [_BINARY, *arguments],
80
+ input=template.encode(),
81
+ capture_output=True,
82
+ check=False,
83
+ )
84
+ if done.returncode != 0:
85
+ message = done.stderr.decode().strip()
86
+ for advice in _SHELL_ADVICE:
87
+ message = message.removesuffix("\n" + advice)
88
+ raise FejkdataError(message, done.returncode)
89
+ return done.stdout.decode()
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: fejkdata/bin/fejkdata.exe
3
+ size: 66105344 bytes
4
+ sha256: 6102d3ba5765fd505056763d00a9e0cb7289b189ae84463428fb651daee4411f
fejkdata/py.typed ADDED
File without changes
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: fejkdata
3
+ Version: 0.9.0
4
+ Summary: Fake data for tests. Related values match, like a postcode and its city.
5
+ Keywords: csv,fake data,fixtures,mock data,national id,seed data,sql,synthetic data,test data,testing
6
+ Project-URL: Homepage, https://fejkdata.dev
7
+ Project-URL: Documentation, https://github.com/larvit/fejkdata#readme
8
+ Project-URL: Source, https://github.com/larvit/fejkdata
9
+ Project-URL: Changelog, https://github.com/larvit/fejkdata/blob/main/CHANGELOG.md
10
+ Project-URL: Issues, https://github.com/larvit/fejkdata/issues
11
+ Author: Larv IT AB
12
+ License-Expression: MIT AND LicenseRef-fejkdata-data-licenses
13
+ License-File: LICENSE
14
+ License-File: DATA-LICENSES.md
15
+ License-File: WORDNET-LICENSE.txt
16
+ Classifier: Development Status :: 4 - Beta
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Operating System :: MacOS
19
+ Classifier: Operating System :: Microsoft :: Windows
20
+ Classifier: Operating System :: POSIX :: Linux
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Programming Language :: Python :: 3.15
27
+ Classifier: Topic :: Software Development :: Testing
28
+ Classifier: Topic :: Software Development :: Testing :: Mocking
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.11
31
+ Description-Content-Type: text/markdown
32
+
33
+ # fejkdata
34
+
35
+ Fake data for tests. Related values match, like a postcode and its city. National ids pass
36
+ validation where possible.
37
+
38
+ ```sh
39
+ pip install fejkdata
40
+ ```
41
+
42
+ It needs Python 3.11 or later. It installs on Linux, macOS and Windows, on amd64 and arm64.
43
+ There is no source build, so pip finds nothing to install on another platform. The package
44
+ doesn't put a `fejkdata` command on your path.
45
+
46
+ ```python
47
+ import fejkdata
48
+
49
+ print(fejkdata.render("{/sv_SE.person}", seed=1, today="2026-01-15"))
50
+ ```
51
+
52
+ ```text
53
+ Felix Östberg
54
+ ```
55
+
56
+ `render` returns what the [fejkdata CLI](https://github.com/larvit/fejkdata#cli) prints
57
+ for the same template, seed and day. The package carries the CLI and all its data. It
58
+ doesn't fetch anything when it runs, and it doesn't depend on any other package.
59
+
60
+ ## Arguments
61
+
62
+ `render(template, *, seed, today, repeat=1, format="text", table=None, data_path=None,
63
+ no_shipped_data=False, separator=None, null_text=None)` returns a `str`.
64
+
65
+ - `template` is a string. It holds a format string or JSON text. Pass a dict through
66
+ `json.dumps` first.
67
+ - `seed` is a whole number from 0 up. You must pass it by name. The same seed and day give
68
+ the same text.
69
+ - `today` is a `datetime.date` or a string like `"2026-01-15"`. You must pass it by name
70
+ too. Ages and dates count from this day.
71
+ - `repeat` is how many times to render the template. It defaults to 1.
72
+ - `format` is `"text"` unless you ask for records. Records come as `"csv"`, `"json"`,
73
+ `"ndjson"`, `"pgcopy"`, `"sql"` or `"tsv"`.
74
+ - `table` is the table `"sql"` and `"pgcopy"` write to. Without it, `{/sv_SE.person}` writes
75
+ to the table `person`, its last segment without any `[…]` selector, and any other record
76
+ to `records`. Any other format ignores `table`.
77
+ - `data_path` is a folder of your own categories, as a string or a `pathlib.Path`, or a list
78
+ of them. The folders layer over the shipped data, and the last one wins on a clash.
79
+ - `no_shipped_data=True` loads only the `data_path` folders.
80
+ - `separator` is the text between repeated renders. It is empty by default, and the CLI
81
+ refuses it with a record format.
82
+ - `null_text` is what `"csv"` writes for a null column, instead of an empty field. The CLI
83
+ refuses it under any other format. Write a text such as `\N` as `r"\N"`, since `"\N"` is
84
+ a syntax error in Python.
85
+
86
+ Each of the last five passes the flag of its name, such as `--null-text`, and the
87
+ [CLI's flags](https://github.com/larvit/fejkdata#cli) say more.
88
+
89
+ ```python
90
+ import json
91
+
92
+ person = {"format": "{/sv_SE.person as p}", "first": "{p.first}", "last": "{p.last}"}
93
+ rows = fejkdata.render(json.dumps(person), seed=1, today="2026-01-15", repeat=1000, format="csv")
94
+ print(rows.splitlines()[:3])
95
+ ```
96
+
97
+ ```text
98
+ ['first,last', 'Vinston,Larsson', 'Felix,Lind']
99
+ ```
100
+
101
+ ```python
102
+ sql = fejkdata.render(json.dumps(person), seed=1, today="2026-01-15", repeat=2, format="sql", table="people")
103
+ print(sql)
104
+ ```
105
+
106
+ ```text
107
+ INSERT INTO "people" ("first", "last") VALUES ('Vinston', 'Larsson'),('Felix', 'Lind');
108
+
109
+ ```
110
+
111
+ ## Paths
112
+
113
+ `paths(*, data_path=None, no_shipped_data=False)` returns every path the data offers, as a
114
+ list of strings in the order `fejkdata --list` prints them. Its two arguments mean what they
115
+ do for `render`, so a folder in `data_path` adds its paths to the list. A path has no leading
116
+ slash: a template writes `sv_SE.person` as `{/sv_SE.person}`.
117
+
118
+ ```python
119
+ print(" ".join(path for path in fejkdata.paths() if path.startswith("sv_SE.address.")))
120
+ ```
121
+
122
+ ```text
123
+ sv_SE.address.locality sv_SE.address.municipality sv_SE.address.postal-code sv_SE.address.region sv_SE.address.street sv_SE.address.street-number
124
+ ```
125
+
126
+ ## Errors
127
+
128
+ A call the CLI refuses, `render` or `paths`, raises `fejkdata.FejkdataError`. Its message is the
129
+ CLI's error text, and its `returncode` is the CLI's exit code.
130
+
131
+ The [README](https://github.com/larvit/fejkdata#readme) documents templates and the
132
+ shipped data.
@@ -0,0 +1,9 @@
1
+ fejkdata/__init__.py,sha256=bZ_tjj9vLzcnccvxiUeMmMdlnanHgMfKaen6tp894Bc,3249
2
+ fejkdata/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ fejkdata-0.9.0.dist-info/METADATA,sha256=IYXTG8iovomMvwP_9__UP_v3v2IAyfk2e2I6W_eHHp0,5350
4
+ fejkdata-0.9.0.dist-info/WHEEL,sha256=DFaj4DCiRabuxKr_wTeBX_3kzFaew2mjJ01c77YPMV8,102
5
+ fejkdata-0.9.0.dist-info/licenses/LICENSE,sha256=qSzKQvygD9atjsv08VrkqJCApK6XHE771aqfDiMx-fI,1095
6
+ fejkdata-0.9.0.dist-info/licenses/DATA-LICENSES.md,sha256=SNcSibwBa1BUB0U18HQSWzLFxbDqYUK4okW1ZTwhfPg,69290
7
+ fejkdata-0.9.0.dist-info/licenses/WORDNET-LICENSE.txt,sha256=5Raiu1Fvm_fpcQ_8i5FlzqPcxNrr8kJqnVn9UctEvg0,1561
8
+ fejkdata/bin/fejkdata.exe,sha256=YQLTuldl_VBQVnY9AKngy3KJsYmuhEY0KPtlHa7kQR8,66105344
9
+ fejkdata-0.9.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: fejkdata release-tooling
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64