dataforger 0.1.1__tar.gz → 0.1.3__tar.gz
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.
- dataforger-0.1.3/PKG-INFO +263 -0
- dataforger-0.1.3/README.md +214 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/pyproject.toml +17 -1
- dataforger-0.1.3/src/dataforger/__init__.py +23 -0
- dataforger-0.1.3/src/dataforger/api.py +284 -0
- dataforger-0.1.3/src/dataforger/cli.py +211 -0
- dataforger-0.1.3/src/dataforger/datasets.py +263 -0
- dataforger-0.1.3/src/dataforger.egg-info/PKG-INFO +263 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger.egg-info/SOURCES.txt +5 -1
- dataforger-0.1.3/tests/test_api.py +120 -0
- dataforger-0.1.3/tests/test_cli.py +97 -0
- dataforger-0.1.3/tests/test_datasets.py +109 -0
- dataforger-0.1.1/PKG-INFO +0 -106
- dataforger-0.1.1/README.md +0 -69
- dataforger-0.1.1/src/dataforger/__init__.py +0 -3
- dataforger-0.1.1/src/dataforger/cli.py +0 -98
- dataforger-0.1.1/src/dataforger.egg-info/PKG-INFO +0 -106
- dataforger-0.1.1/tests/test_cli.py +0 -47
- {dataforger-0.1.1 → dataforger-0.1.3}/LICENSE +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/setup.cfg +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger/core.py +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger/countries.json +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger/data.json +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger.egg-info/dependency_links.txt +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger.egg-info/entry_points.txt +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/src/dataforger.egg-info/top_level.txt +0 -0
- {dataforger-0.1.1 → dataforger-0.1.3}/tests/test_core.py +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dataforger
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Generate fake data from Python or the command line.
|
|
5
|
+
Author-email: Karmanshi Shrivastava <karmanshishrivastava20@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Karmanshi Shrivastava
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/karmanshi/dataforger
|
|
29
|
+
Project-URL: Repository, https://github.com/karmanshi/dataforger
|
|
30
|
+
Project-URL: Issues, https://github.com/karmanshi/dataforger/issues
|
|
31
|
+
Keywords: fake-data,data-generation,csv,json,testing,cli
|
|
32
|
+
Classifier: Development Status :: 3 - Alpha
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
42
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
43
|
+
Classifier: Topic :: Software Development :: Testing
|
|
44
|
+
Classifier: Topic :: Utilities
|
|
45
|
+
Requires-Python: >=3.10
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# dataforger
|
|
51
|
+
|
|
52
|
+
Generate realistic fake data from Python or the command line, and save it as
|
|
53
|
+
CSV or JSON. Dataforger uses only the Python standard library and has no
|
|
54
|
+
third-party runtime dependencies.
|
|
55
|
+
|
|
56
|
+
Built-in names, streets, companies, and email domains are stored in
|
|
57
|
+
`src/dataforger/data.json`. Country names and their associated cities are
|
|
58
|
+
stored in `src/dataforger/countries.json`; when generating a record with both
|
|
59
|
+
country and city fields, the city is selected from that country's list.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
Requires Python 3.10 or later.
|
|
64
|
+
|
|
65
|
+
From a checkout of this repository:
|
|
66
|
+
|
|
67
|
+
```console
|
|
68
|
+
python -m pip install .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After publishing the package to PyPI:
|
|
72
|
+
|
|
73
|
+
```console
|
|
74
|
+
python -m pip install dataforger
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Publishing to PyPI
|
|
78
|
+
|
|
79
|
+
The GitHub Actions workflow runs the tests on Python 3.10 through 3.13 and
|
|
80
|
+
builds wheel and source distributions on pushes and pull requests. To publish,
|
|
81
|
+
configure a PyPI trusted publisher for this GitHub repository, using workflow
|
|
82
|
+
`.github/workflows/publish.yml` and the GitHub environment `pypi`. Then create
|
|
83
|
+
and publish a GitHub Release; the workflow publishes its tested distributions
|
|
84
|
+
to PyPI using trusted publishing.
|
|
85
|
+
|
|
86
|
+
## Command line
|
|
87
|
+
|
|
88
|
+
Run `dataforger` without field options for an interactive prompt. Or specify
|
|
89
|
+
all options directly:
|
|
90
|
+
|
|
91
|
+
```console
|
|
92
|
+
dataforger --rows 100 --field name:name --field email:email --field age:age --format csv --output users.csv --seed 42
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### CLI options
|
|
96
|
+
|
|
97
|
+
| Option | Description | Default |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `--field NAME:TYPE` | Output column name and the type of value to generate. Repeat to add fields. | Prompts for fields if omitted |
|
|
100
|
+
| `--rows COUNT` | Number of records. Must be a positive integer. | `10` |
|
|
101
|
+
| `--format {csv,json}` | Output format; in dataset mode, exports saved records. | `json` |
|
|
102
|
+
| `--output PATH` | Path for generated or exported records. | `data.json` or `data.csv`, based on format |
|
|
103
|
+
| `--seed INTEGER` | Seed for repeatable output. | Random |
|
|
104
|
+
| `--dataset KEY` | Reuse or create a persistent JSON dataset instead of writing an output file. | |
|
|
105
|
+
| `--replace-dataset` | Regenerate and replace an existing persistent dataset; requires `--dataset`. | |
|
|
106
|
+
| `--data-dir PATH` | Directory for persistent datasets. | `~/.dataforger/datasets` |
|
|
107
|
+
|
|
108
|
+
`NAME` is the column/key to write in the output; choose any non-empty name.
|
|
109
|
+
`TYPE` must be one of the supported field types below. For example,
|
|
110
|
+
`--field first_name:first_name` creates a column named `first_name` using
|
|
111
|
+
generated first names, while `--field given:first_name` creates the same kind
|
|
112
|
+
of values under the column name `given`.
|
|
113
|
+
|
|
114
|
+
### Supported field types
|
|
115
|
+
|
|
116
|
+
| Type | Generated value |
|
|
117
|
+
| --- | --- |
|
|
118
|
+
| `name` | Full name |
|
|
119
|
+
| `first_name` | First name |
|
|
120
|
+
| `last_name` | Last name |
|
|
121
|
+
| `email` | Email address using a reserved example domain |
|
|
122
|
+
| `phone` | Phone-like number |
|
|
123
|
+
| `address` | Street address including a generated city |
|
|
124
|
+
| `city` | City from the bundled country-to-city data |
|
|
125
|
+
| `country` | Country from the bundled country-to-city data |
|
|
126
|
+
| `company` | Company name |
|
|
127
|
+
| `uuid` | UUID |
|
|
128
|
+
| `date` | Date between 1970-01-01 and today |
|
|
129
|
+
| `age` | Integer from 0 to 100 |
|
|
130
|
+
| `integer` | Integer from 0 to 100,000 |
|
|
131
|
+
| `float` | Decimal value from 0 to 100,000 |
|
|
132
|
+
| `boolean` | `true` or `false` |
|
|
133
|
+
|
|
134
|
+
When a record requests both `country` and `city`, the city is selected from
|
|
135
|
+
that country's city list. If it also requests `address`, its city matches
|
|
136
|
+
those fields.
|
|
137
|
+
|
|
138
|
+
## Python API
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from dataforger import generate_data, write_data
|
|
142
|
+
|
|
143
|
+
records = generate_data(
|
|
144
|
+
{
|
|
145
|
+
"first_name": "first_name",
|
|
146
|
+
"last_name": "last_name",
|
|
147
|
+
"country": "country",
|
|
148
|
+
"city": "city",
|
|
149
|
+
"email": "email",
|
|
150
|
+
"age": "age",
|
|
151
|
+
},
|
|
152
|
+
rows=100,
|
|
153
|
+
seed=42,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
write_data(records, "users.json", "json")
|
|
157
|
+
write_data(records, "users.csv", "csv")
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`generate_data` returns a list of dictionaries. Pass the resulting records,
|
|
161
|
+
an output path, and either `"csv"` or `"json"` to `write_data`.
|
|
162
|
+
Its parameters are `fields` (a mapping of output column names to supported
|
|
163
|
+
types), `rows` (positive record count), and optional `seed` (integer for
|
|
164
|
+
repeatable values). `write_data` takes `records`, `output` (path), and
|
|
165
|
+
`format` (`"csv"` or `"json"`).
|
|
166
|
+
|
|
167
|
+
### Persistent datasets
|
|
168
|
+
|
|
169
|
+
Persistent datasets let separate CLI runs, Python calls, and REST requests
|
|
170
|
+
reuse exactly the same records. Use a unique key for each dataset:
|
|
171
|
+
|
|
172
|
+
```console
|
|
173
|
+
dataforger --dataset customers --field id:uuid --field name:name --rows 100 --seed 42
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Repeat the same command to load the saved records rather than generating new
|
|
177
|
+
ones. By default, a key cannot be reused with different fields, row counts, or
|
|
178
|
+
seed; Dataforger reports a conflict instead of silently changing the fixture.
|
|
179
|
+
Use `--replace-dataset` to explicitly regenerate it. Dataset keys are limited
|
|
180
|
+
to letters, numbers, dots, underscores, and hyphens.
|
|
181
|
+
To retrieve a dataset without supplying its generation parameters, omit
|
|
182
|
+
`--field`; use `--output` and `--format` to export the saved records:
|
|
183
|
+
|
|
184
|
+
```console
|
|
185
|
+
dataforger --dataset customers --format csv --output customers.csv
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Datasets are stored as JSON files in `~/.dataforger/datasets` by default. Set
|
|
189
|
+
`DATAFORGER_DATA_DIR` to share another location across CLI and Python usage,
|
|
190
|
+
or pass `--data-dir PATH` to the CLI. The API server uses the same configured
|
|
191
|
+
directory; `dataforger --serve --data-dir PATH` sets it for that server.
|
|
192
|
+
Writes are atomic and serialized across threads and processes on the same
|
|
193
|
+
machine. For containerized deployments, mount a persistent volume at the
|
|
194
|
+
configured directory.
|
|
195
|
+
|
|
196
|
+
The Python API exposes the same operations:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from dataforger import get_dataset, get_or_create_dataset, replace_dataset
|
|
200
|
+
|
|
201
|
+
customers = get_or_create_dataset(
|
|
202
|
+
"customers",
|
|
203
|
+
{"id": "uuid", "name": "name"},
|
|
204
|
+
rows=100,
|
|
205
|
+
seed=42,
|
|
206
|
+
)
|
|
207
|
+
same_customers = get_dataset("customers")
|
|
208
|
+
replacement = replace_dataset(
|
|
209
|
+
"customers",
|
|
210
|
+
{"id": "uuid", "name": "name"},
|
|
211
|
+
rows=100,
|
|
212
|
+
seed=43,
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`get_or_create_dataset` returns an existing dataset only when the generation
|
|
217
|
+
parameters match. It raises `DatasetConflictError` when they differ and
|
|
218
|
+
`DatasetNotFoundError` is raised when `get_dataset` cannot find a key.
|
|
219
|
+
`replace_dataset` explicitly generates and stores a replacement. All three
|
|
220
|
+
functions accept an optional `directory` argument to override the default
|
|
221
|
+
store directory.
|
|
222
|
+
|
|
223
|
+
## HTTP API
|
|
224
|
+
|
|
225
|
+
Start the built-in HTTP API with:
|
|
226
|
+
|
|
227
|
+
```console
|
|
228
|
+
dataforger --serve
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The server listens on `127.0.0.1:8000` by default. Use `--host` and `--port`
|
|
232
|
+
to change the bind address and port. The API has no authentication, so keep it
|
|
233
|
+
on localhost unless you put it behind an appropriately secured service.
|
|
234
|
+
|
|
235
|
+
Generate records with a JSON `POST` request to `/api/v1/generate`:
|
|
236
|
+
|
|
237
|
+
```console
|
|
238
|
+
curl -X POST http://127.0.0.1:8000/api/v1/generate ^
|
|
239
|
+
-H "Content-Type: application/json" ^
|
|
240
|
+
-d "{\"fields\":{\"name\":\"name\",\"email\":\"email\",\"age\":\"age\"},\"rows\":2,\"seed\":42}"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`fields` is a mapping of output names to supported field types, `rows` is
|
|
244
|
+
optional (defaults to `10`, maximum `10000`), and `seed` is optional. The
|
|
245
|
+
request body is limited to 1 MiB and `fields` to 100 entries. Responses use
|
|
246
|
+
JSON; successful generation returns `{"count": 2, "data": [...]}`, and invalid
|
|
247
|
+
requests return a JSON `error` with an appropriate HTTP status.
|
|
248
|
+
|
|
249
|
+
`GET /api/v1/fields` lists supported field types. `GET /health` returns the
|
|
250
|
+
server health status.
|
|
251
|
+
|
|
252
|
+
Persistent datasets use:
|
|
253
|
+
|
|
254
|
+
* `POST /api/v1/datasets` with `key`, `fields`, and optional `rows` and `seed`
|
|
255
|
+
to create or reuse a dataset. Reusing the key with different generation
|
|
256
|
+
parameters returns `409 Conflict`.
|
|
257
|
+
* `GET /api/v1/datasets/{key}` to retrieve a saved dataset.
|
|
258
|
+
* `PUT /api/v1/datasets/{key}` with `fields` and optional `rows` and `seed` to
|
|
259
|
+
explicitly generate or replace the dataset.
|
|
260
|
+
|
|
261
|
+
These routes use the same JSON file store as the Python and CLI interfaces.
|
|
262
|
+
The API has no authentication; keep it bound to localhost unless protected by
|
|
263
|
+
an appropriately secured service.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# dataforger
|
|
2
|
+
|
|
3
|
+
Generate realistic fake data from Python or the command line, and save it as
|
|
4
|
+
CSV or JSON. Dataforger uses only the Python standard library and has no
|
|
5
|
+
third-party runtime dependencies.
|
|
6
|
+
|
|
7
|
+
Built-in names, streets, companies, and email domains are stored in
|
|
8
|
+
`src/dataforger/data.json`. Country names and their associated cities are
|
|
9
|
+
stored in `src/dataforger/countries.json`; when generating a record with both
|
|
10
|
+
country and city fields, the city is selected from that country's list.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Requires Python 3.10 or later.
|
|
15
|
+
|
|
16
|
+
From a checkout of this repository:
|
|
17
|
+
|
|
18
|
+
```console
|
|
19
|
+
python -m pip install .
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
After publishing the package to PyPI:
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
python -m pip install dataforger
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Publishing to PyPI
|
|
29
|
+
|
|
30
|
+
The GitHub Actions workflow runs the tests on Python 3.10 through 3.13 and
|
|
31
|
+
builds wheel and source distributions on pushes and pull requests. To publish,
|
|
32
|
+
configure a PyPI trusted publisher for this GitHub repository, using workflow
|
|
33
|
+
`.github/workflows/publish.yml` and the GitHub environment `pypi`. Then create
|
|
34
|
+
and publish a GitHub Release; the workflow publishes its tested distributions
|
|
35
|
+
to PyPI using trusted publishing.
|
|
36
|
+
|
|
37
|
+
## Command line
|
|
38
|
+
|
|
39
|
+
Run `dataforger` without field options for an interactive prompt. Or specify
|
|
40
|
+
all options directly:
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
dataforger --rows 100 --field name:name --field email:email --field age:age --format csv --output users.csv --seed 42
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### CLI options
|
|
47
|
+
|
|
48
|
+
| Option | Description | Default |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `--field NAME:TYPE` | Output column name and the type of value to generate. Repeat to add fields. | Prompts for fields if omitted |
|
|
51
|
+
| `--rows COUNT` | Number of records. Must be a positive integer. | `10` |
|
|
52
|
+
| `--format {csv,json}` | Output format; in dataset mode, exports saved records. | `json` |
|
|
53
|
+
| `--output PATH` | Path for generated or exported records. | `data.json` or `data.csv`, based on format |
|
|
54
|
+
| `--seed INTEGER` | Seed for repeatable output. | Random |
|
|
55
|
+
| `--dataset KEY` | Reuse or create a persistent JSON dataset instead of writing an output file. | |
|
|
56
|
+
| `--replace-dataset` | Regenerate and replace an existing persistent dataset; requires `--dataset`. | |
|
|
57
|
+
| `--data-dir PATH` | Directory for persistent datasets. | `~/.dataforger/datasets` |
|
|
58
|
+
|
|
59
|
+
`NAME` is the column/key to write in the output; choose any non-empty name.
|
|
60
|
+
`TYPE` must be one of the supported field types below. For example,
|
|
61
|
+
`--field first_name:first_name` creates a column named `first_name` using
|
|
62
|
+
generated first names, while `--field given:first_name` creates the same kind
|
|
63
|
+
of values under the column name `given`.
|
|
64
|
+
|
|
65
|
+
### Supported field types
|
|
66
|
+
|
|
67
|
+
| Type | Generated value |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `name` | Full name |
|
|
70
|
+
| `first_name` | First name |
|
|
71
|
+
| `last_name` | Last name |
|
|
72
|
+
| `email` | Email address using a reserved example domain |
|
|
73
|
+
| `phone` | Phone-like number |
|
|
74
|
+
| `address` | Street address including a generated city |
|
|
75
|
+
| `city` | City from the bundled country-to-city data |
|
|
76
|
+
| `country` | Country from the bundled country-to-city data |
|
|
77
|
+
| `company` | Company name |
|
|
78
|
+
| `uuid` | UUID |
|
|
79
|
+
| `date` | Date between 1970-01-01 and today |
|
|
80
|
+
| `age` | Integer from 0 to 100 |
|
|
81
|
+
| `integer` | Integer from 0 to 100,000 |
|
|
82
|
+
| `float` | Decimal value from 0 to 100,000 |
|
|
83
|
+
| `boolean` | `true` or `false` |
|
|
84
|
+
|
|
85
|
+
When a record requests both `country` and `city`, the city is selected from
|
|
86
|
+
that country's city list. If it also requests `address`, its city matches
|
|
87
|
+
those fields.
|
|
88
|
+
|
|
89
|
+
## Python API
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from dataforger import generate_data, write_data
|
|
93
|
+
|
|
94
|
+
records = generate_data(
|
|
95
|
+
{
|
|
96
|
+
"first_name": "first_name",
|
|
97
|
+
"last_name": "last_name",
|
|
98
|
+
"country": "country",
|
|
99
|
+
"city": "city",
|
|
100
|
+
"email": "email",
|
|
101
|
+
"age": "age",
|
|
102
|
+
},
|
|
103
|
+
rows=100,
|
|
104
|
+
seed=42,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
write_data(records, "users.json", "json")
|
|
108
|
+
write_data(records, "users.csv", "csv")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`generate_data` returns a list of dictionaries. Pass the resulting records,
|
|
112
|
+
an output path, and either `"csv"` or `"json"` to `write_data`.
|
|
113
|
+
Its parameters are `fields` (a mapping of output column names to supported
|
|
114
|
+
types), `rows` (positive record count), and optional `seed` (integer for
|
|
115
|
+
repeatable values). `write_data` takes `records`, `output` (path), and
|
|
116
|
+
`format` (`"csv"` or `"json"`).
|
|
117
|
+
|
|
118
|
+
### Persistent datasets
|
|
119
|
+
|
|
120
|
+
Persistent datasets let separate CLI runs, Python calls, and REST requests
|
|
121
|
+
reuse exactly the same records. Use a unique key for each dataset:
|
|
122
|
+
|
|
123
|
+
```console
|
|
124
|
+
dataforger --dataset customers --field id:uuid --field name:name --rows 100 --seed 42
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Repeat the same command to load the saved records rather than generating new
|
|
128
|
+
ones. By default, a key cannot be reused with different fields, row counts, or
|
|
129
|
+
seed; Dataforger reports a conflict instead of silently changing the fixture.
|
|
130
|
+
Use `--replace-dataset` to explicitly regenerate it. Dataset keys are limited
|
|
131
|
+
to letters, numbers, dots, underscores, and hyphens.
|
|
132
|
+
To retrieve a dataset without supplying its generation parameters, omit
|
|
133
|
+
`--field`; use `--output` and `--format` to export the saved records:
|
|
134
|
+
|
|
135
|
+
```console
|
|
136
|
+
dataforger --dataset customers --format csv --output customers.csv
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Datasets are stored as JSON files in `~/.dataforger/datasets` by default. Set
|
|
140
|
+
`DATAFORGER_DATA_DIR` to share another location across CLI and Python usage,
|
|
141
|
+
or pass `--data-dir PATH` to the CLI. The API server uses the same configured
|
|
142
|
+
directory; `dataforger --serve --data-dir PATH` sets it for that server.
|
|
143
|
+
Writes are atomic and serialized across threads and processes on the same
|
|
144
|
+
machine. For containerized deployments, mount a persistent volume at the
|
|
145
|
+
configured directory.
|
|
146
|
+
|
|
147
|
+
The Python API exposes the same operations:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from dataforger import get_dataset, get_or_create_dataset, replace_dataset
|
|
151
|
+
|
|
152
|
+
customers = get_or_create_dataset(
|
|
153
|
+
"customers",
|
|
154
|
+
{"id": "uuid", "name": "name"},
|
|
155
|
+
rows=100,
|
|
156
|
+
seed=42,
|
|
157
|
+
)
|
|
158
|
+
same_customers = get_dataset("customers")
|
|
159
|
+
replacement = replace_dataset(
|
|
160
|
+
"customers",
|
|
161
|
+
{"id": "uuid", "name": "name"},
|
|
162
|
+
rows=100,
|
|
163
|
+
seed=43,
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
`get_or_create_dataset` returns an existing dataset only when the generation
|
|
168
|
+
parameters match. It raises `DatasetConflictError` when they differ and
|
|
169
|
+
`DatasetNotFoundError` is raised when `get_dataset` cannot find a key.
|
|
170
|
+
`replace_dataset` explicitly generates and stores a replacement. All three
|
|
171
|
+
functions accept an optional `directory` argument to override the default
|
|
172
|
+
store directory.
|
|
173
|
+
|
|
174
|
+
## HTTP API
|
|
175
|
+
|
|
176
|
+
Start the built-in HTTP API with:
|
|
177
|
+
|
|
178
|
+
```console
|
|
179
|
+
dataforger --serve
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The server listens on `127.0.0.1:8000` by default. Use `--host` and `--port`
|
|
183
|
+
to change the bind address and port. The API has no authentication, so keep it
|
|
184
|
+
on localhost unless you put it behind an appropriately secured service.
|
|
185
|
+
|
|
186
|
+
Generate records with a JSON `POST` request to `/api/v1/generate`:
|
|
187
|
+
|
|
188
|
+
```console
|
|
189
|
+
curl -X POST http://127.0.0.1:8000/api/v1/generate ^
|
|
190
|
+
-H "Content-Type: application/json" ^
|
|
191
|
+
-d "{\"fields\":{\"name\":\"name\",\"email\":\"email\",\"age\":\"age\"},\"rows\":2,\"seed\":42}"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`fields` is a mapping of output names to supported field types, `rows` is
|
|
195
|
+
optional (defaults to `10`, maximum `10000`), and `seed` is optional. The
|
|
196
|
+
request body is limited to 1 MiB and `fields` to 100 entries. Responses use
|
|
197
|
+
JSON; successful generation returns `{"count": 2, "data": [...]}`, and invalid
|
|
198
|
+
requests return a JSON `error` with an appropriate HTTP status.
|
|
199
|
+
|
|
200
|
+
`GET /api/v1/fields` lists supported field types. `GET /health` returns the
|
|
201
|
+
server health status.
|
|
202
|
+
|
|
203
|
+
Persistent datasets use:
|
|
204
|
+
|
|
205
|
+
* `POST /api/v1/datasets` with `key`, `fields`, and optional `rows` and `seed`
|
|
206
|
+
to create or reuse a dataset. Reusing the key with different generation
|
|
207
|
+
parameters returns `409 Conflict`.
|
|
208
|
+
* `GET /api/v1/datasets/{key}` to retrieve a saved dataset.
|
|
209
|
+
* `PUT /api/v1/datasets/{key}` with `fields` and optional `rows` and `seed` to
|
|
210
|
+
explicitly generate or replace the dataset.
|
|
211
|
+
|
|
212
|
+
These routes use the same JSON file store as the Python and CLI interfaces.
|
|
213
|
+
The API has no authentication; keep it bound to localhost unless protected by
|
|
214
|
+
an appropriately secured service.
|
|
@@ -4,23 +4,39 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "dataforger"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.3"
|
|
8
8
|
description = "Generate fake data from Python or the command line."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Karmanshi Shrivastava", email = "karmanshishrivastava20@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["fake-data", "data-generation", "csv", "json", "testing", "cli"]
|
|
12
16
|
classifiers = [
|
|
13
17
|
"Development Status :: 3 - Alpha",
|
|
14
18
|
"Environment :: Console",
|
|
15
19
|
"Intended Audience :: Developers",
|
|
16
20
|
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
17
22
|
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
18
27
|
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Topic :: Software Development :: Testing",
|
|
29
|
+
"Topic :: Utilities",
|
|
19
30
|
]
|
|
20
31
|
|
|
21
32
|
[project.scripts]
|
|
22
33
|
dataforger = "dataforger.cli:main"
|
|
23
34
|
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/karmanshi/dataforger"
|
|
37
|
+
Repository = "https://github.com/karmanshi/dataforger"
|
|
38
|
+
Issues = "https://github.com/karmanshi/dataforger/issues"
|
|
39
|
+
|
|
24
40
|
[tool.setuptools.packages.find]
|
|
25
41
|
where = ["src"]
|
|
26
42
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from dataforger.core import FIELD_TYPES, generate_data, write_data
|
|
2
|
+
from dataforger.datasets import (
|
|
3
|
+
Dataset,
|
|
4
|
+
DatasetConflictError,
|
|
5
|
+
DatasetIntegrityError,
|
|
6
|
+
DatasetNotFoundError,
|
|
7
|
+
get_dataset,
|
|
8
|
+
get_or_create_dataset,
|
|
9
|
+
replace_dataset,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"FIELD_TYPES",
|
|
14
|
+
"Dataset",
|
|
15
|
+
"DatasetConflictError",
|
|
16
|
+
"DatasetIntegrityError",
|
|
17
|
+
"DatasetNotFoundError",
|
|
18
|
+
"generate_data",
|
|
19
|
+
"get_dataset",
|
|
20
|
+
"get_or_create_dataset",
|
|
21
|
+
"replace_dataset",
|
|
22
|
+
"write_data",
|
|
23
|
+
]
|