https://github.com/perchunpak/optional-faker
Small wrapper around faker, to make values optional!
https://github.com/perchunpak/optional-faker
Last synced: about 1 year ago
JSON representation
Small wrapper around faker, to make values optional!
- Host: GitHub
- URL: https://github.com/perchunpak/optional-faker
- Owner: PerchunPak
- License: gpl-3.0
- Created: 2022-11-13T10:57:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T21:52:28.000Z (over 2 years ago)
- Last Synced: 2025-04-30T23:09:09.813Z (about 1 year ago)
- Language: Python
- Size: 213 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# optional-faker
[](https://www.gov.uk/government/news/ukraine-what-you-can-do-to-help)
[](https://github.com/PerchunPak/optional-faker/actions?query=workflow%3Atest)
[](https://github.com/psf/black)
[](https://www.python.org/downloads/)
Small wrapper around faker, to make values optional!
Note that faker added own `optional` proxy, which however can be used only with callables. This is why in version 2.0.0 we renamed our method to `none_or`.
## Example
```py
>>> from faker import Faker
>>> import optional_faker
>>>
>>> fake = Faker()
>>> Faker.seed(1555)
>>>
>>> # `fake.none_or` can take any value, and return it, or None.
>>> fake.none_or(fake.pystr())
'scHhghRDleajCHjEYWAu'
>>> fake.none_or(fake.pystr())
None
>>> # or it can take callable, and *args with **kwargs
>>> # that will be passed to this callable.
>>> fake.none_or(fake.pystr, 1, max_chars=10)
'zmZUcJVTYX'
>>> fake.none_or(fake.pystr, 1, max_chars=10)
None
>>> # there is no explicit check is callable a faker part,
>>> # so you can pass anything.
>>> fake.none_or(lambda: "my callable!")
'my callable!'
>>> fake.none_or(lambda: "my callable!")
None
```
## Installing
```bash
pip install optional-faker
```
And then you need to import `optional_faker` anywhere but before creating `Faker` instance.
## Installing for local developing
```bash
git clone https://github.com/PerchunPak/optional-faker.git
cd optional-faker
```
### Installing `poetry`
Next we need install `poetry` with [recommended way](https://python-poetry.org/docs/master/#installation).
If you use Linux, use command:
```bash
curl -sSL https://install.python-poetry.org | python -
```
If you use Windows, open PowerShell with admin privileges and use:
```powershell
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
```
### Installing dependencies
```bash
poetry install
```
### If something is not clear
You can always write me!
## Updating
```bash
pip install -U optional-faker
```
### For local development
For updating, just re-download repository,
if you used `git` for downloading, just run `git pull`.
## Thanks
This project was inspired by [faker-optional](https://github.com/lyz-code/faker-optional).
This project was generated with [python-template](https://github.com/PerchunPak/python-template).