A simple Excel files mocker based on faker and pyexcel
Project description
Fexcel
A simple mock excel generator. fexcel reads a JSON file declaring the excel schema to use and creates a new excel file with said configuration.
Content
Installation
Install fexcel with pip
pip install fexcel
check the installation was successful
fexcel --help
Plugins
fexcel relies on faker to generate quality mock data and pyexcel for excel file handling.
As pyexcel has a plugin structure, fexcel has a plugin structure too, and to work with each different kind of file a dedicated pyexcel plugin should be installed.
As a commodity, several extras can be installed alongside fexcel to work with the most usual file type (based on pyexcel own plugin table). The following table lists them:
| extra | file types |
|---|---|
| csv | .csv, .tsv, .csvz and .tsvz |
| xls | .xls |
| xlsx | .xlsx |
| ods | .ods |
| all | All of the above |
Therefore, to handle .xlsx files you would install fexcel as
pip install 'fexcel[xlsx]'
Usage
CLI
You can use the command line to create a fake excel based on an existing schema declaration
fexcel /path/to/input/schema.json /path/to/output/file.xlsx --num-fakes 100
API
You can leverage fexcel's main interface Fexcel to parse a schema and write the resulting excel in a file as such
from fexcel import Fexcel
fexcel = Fexcel.from_file("schema.json")
fexcel.write_to_file("output.xlsx")
Schema
Fexcel expects to have its schema defined in a JSON file with the following structure
[
{
"name": "FIRST_FIELD_NAME",
"type": "FIRST_FIELD_TYPE",
"constraints": {
"constraint1": "CONSTRAINT_VALUE",
"constraint2": "CONSTRAINT_VALUE"
}
},
{
"name": "SECOND_FIELD_NAME",
"type": "SECOND_FIELD_TYPE",
"constraints": {
"constraint1": "CONSTRAINT_VALUE"
}
}
]
- The
nameattribute defines how the final excel field will be named. - The
typeattribute specifies the data type of the field. - The
constraintsattribute specifies a set of key-value pairs to customize how the data will be generated.
The name and type attributes are required and the constraints attribute is always optional and has a default implementation.
The possible constraints for each type are listed below.
Text Fields
The supported text fields are
| type | description |
|---|---|
| Name | An ordinary randomly generated name |
| A randomly generated e-mail | |
| Phone | A phone address |
| Address | An address of a person or institution |
| UUID | A Universally Unique Identifier |
| Location | A locale string (e.g. en_EN) |
Currently this fields admit no constraints
Numeric Fields
The supported numeric fields are
| type | description |
|---|---|
| float | A random decimal value following some distribution |
| int / integer | A random integer value following some distribution |
The possible constraints are
| constraint | description | values |
|---|---|---|
| distribution | Statistic distribution of the data | uniform (default), normal, or lognormal |
| min_value | Lower bound for the field values, can only be specified with the uniform distribution |
numeric value, defaults to -1e30 |
| max_value | Upper bound for the field values, can only be specified with the uniform distribution |
numeric value, defaults to 1e30 |
| mean | Mean value for normal or lognormal distributions |
numeric value, defaults to 0 |
| std | Standard deviation for normal or lognormal distributions |
numeric value, defaults to 1 |
Choice Fields
The supported choice fields are
| type | description |
|---|---|
| choice | Choose between an array of possible values |
The possible constraints are
| constraint | description | values |
|---|---|---|
| allowed_values | Array of values to choose from when filling the data | Array of string values, defaults to ["NULL"] |
| probabilities | Array of float values defining the probability of each allowed value. Each probability corresponds to the probability of the value in that position, if there are values left unspecified the remaining probability will be equidistributed amongst the remaining values | Array of floating values between 0 and 1. Must sum up to 1 (or less if some probabilities are left unspecified). Defaults to an empty array. |
Temporal fields
The supported temporal fields are
| type | description |
|---|---|
| date | A day of the year in the Gregorian Calendar, without time part |
| time | A time part of a date consisting only on hours, minutes, seconds and microseconds |
| datetime | A date with time part of the Gregorian Calendar |
The possible constraints are
| constraint | description | values |
|---|---|---|
| format_string | The format string to which the values will be displayed | A valid datetime format string, defaults to "%Y-%m-%d %H-%M-%S" for datetime fields and "%Y-%m-%d" for date fields |
| start_date | A date to which all values of the field will precede | A date represented in the format_string representation or in ISO 8601, defaults to 1970-01-01 00:00:00 |
| end_date | A date to which all values of the field will be prior to | A date represented in the format_string representation or in ISO 8601, defaults to the current execution time |
Boolean fields
The supported boolean fields are
| type | description |
|---|---|
| bool / boolean | A boolean True or False value |
The possible constraints are
| constraint | description | values |
|---|---|---|
| probability | The probability for the field to be True |
A number between 0 and 1, defaults to 0.5 |
Network fields
The supported network fields are
| type | description |
|---|---|
| url | HTTP and HTTPS random valid URLs |
| IPv4 | A random IPv4 address or network with a valid CIDR |
| IPv6 | A random IPv6 address or network with a valid CIDR |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fexcel-0.0.2.tar.gz.
File metadata
- Download URL: fexcel-0.0.2.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7ad766b3768b849dd8455676ccab638276a0d07d9775d4cc3f55b888e7019ae
|
|
| MD5 |
520adb2c419924ae05150b905b6a506a
|
|
| BLAKE2b-256 |
b882adbd19909e85d8b2d971d6ee97d1de45290837a5c4294bb7d54fd8ec48f2
|
Provenance
The following attestation bundles were made for fexcel-0.0.2.tar.gz:
Publisher:
publish.yaml on manelcaireta/fexcel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fexcel-0.0.2.tar.gz -
Subject digest:
f7ad766b3768b849dd8455676ccab638276a0d07d9775d4cc3f55b888e7019ae - Sigstore transparency entry: 188321404
- Sigstore integration time:
-
Permalink:
manelcaireta/fexcel@12d0b814bde6aee3bc8a9e4d5aa0e2e68af17a0e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/manelcaireta
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@12d0b814bde6aee3bc8a9e4d5aa0e2e68af17a0e -
Trigger Event:
release
-
Statement type:
File details
Details for the file fexcel-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fexcel-0.0.2-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e272f3649b2e01ba9a7a9c90c600b1c711304e342fa8b5eb5a58b6e7d4cbef18
|
|
| MD5 |
8330ccfc6d4d8b9d1dcc2ec4171598a6
|
|
| BLAKE2b-256 |
f41732978f806dd3531c2a9ae560a09e0d07032ba883cd82554438ea1360931e
|
Provenance
The following attestation bundles were made for fexcel-0.0.2-py3-none-any.whl:
Publisher:
publish.yaml on manelcaireta/fexcel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fexcel-0.0.2-py3-none-any.whl -
Subject digest:
e272f3649b2e01ba9a7a9c90c600b1c711304e342fa8b5eb5a58b6e7d4cbef18 - Sigstore transparency entry: 188321407
- Sigstore integration time:
-
Permalink:
manelcaireta/fexcel@12d0b814bde6aee3bc8a9e4d5aa0e2e68af17a0e -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/manelcaireta
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@12d0b814bde6aee3bc8a9e4d5aa0e2e68af17a0e -
Trigger Event:
release
-
Statement type: