fakedata: Library for producing fake data

[ bsd3, fake, fakedata, library, random ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/psibi/fakedata#readme

[Skip to Readme]
Versions [faq], 0.2.0, 0.2.1, 0.2.2, 0.3.0, 0.3.1, 0.4.0, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.8.0
Change log ChangeLog.md
Dependencies attoparsec, base (>=4.7 && <5), bytestring, containers, directory, exceptions, fakedata-parser, filepath, hashable, random, string-random, template-haskell, text, time, unordered-containers, vector, yaml [details]
License BSD-3-Clause
Copyright Sibi Prabakaran
Author Sibi Prabakaran
Maintainer sibi@psibi.in
Category Random, Fake, FakeData
Home page https://github.com/psibi/fakedata#readme
Bug tracker https://github.com/psibi/fakedata/issues
Source repo head: git clone https://github.com/psibi/fakedata
Uploaded by psibi at 2020-09-29T07:01:33Z
Distributions NixOS:0.8.0, Stackage:0.2.1
Downloads 3607 total (23 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-09-29 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for fakedata-0.8.0

[back to package description]

fakedata Hackage Stackage
Nightly Stackage
LTS Build Status

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> **Table of Contents** <!-- markdown-toc end -->


This library is a port of Ruby's faker. It's a library for producing fake data such as names, addressess and phone numbers. Note that it directly uses the source data from that library, so the quality of fake data is quite high!


Generating address

~/g/fakedata (master) $ stack ghci
λ> import Faker.Address
λ> address <- generate fullAddress
λ> address
"Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259"

Generating name

λ> fullName <- generate name
λ> fullName
"Sherryl Steuber"

Generate quotes from the movie Back to the Future

λ> import Faker.Movie.BackToTheFuture
λ> import Faker.Combinators
λ> qs <- generateNonDeterministic $ listOf 5 quotes
λ> qs
[ "Yes. Yes. I'm George. George McFly. I'm your density. I mean, your destiny."
, "Hello? Hello? Anybody home? Huh? Think, McFly. Think! I gotta have time to get them retyped. Do you realize what would happen if I hand in my reports in your handwriting? I'll get fired. You wouldn't want that to happen, would ya? Would ya?"
, "Lorraine. My density has brought me to you."
, "See you in about 30 years."
, "You really think I ought to swear?"

Combining Fake datas

{-#LANGUAGE RecordWildCards#-}

import Faker
import Faker.Name
import Faker.Address
import Data.Text

data Person = Person {
    personName :: Text,
    personAddress :: Text
} deriving (Show, Eq)

fakePerson :: Fake Person
fakePerson = do
    personName <- name
    personAddress <- fullAddress
    pure $ Person{..}

main :: IO ()
main = do
    person <- generate fakePerson
    print person

And on executing them:

$ stack name.hs
  { personName = "Sherryl Steuber"
  , personAddress = "Apt. 298 340 Ike Mission, Goldnertown, FL 19488-9259"

You would have noticed in the above output that the name and address are the same as generated before in the GHCi REPL. That's because, by default all the generated data are deterministic. If you want a different set of output each time, you would have to modify the random generator output:

main :: IO ()
main = do
    gen <- newStdGen
    let settings = setRandomGen gen defaultFakerSettings
    person <- generateWithSettings settings fakePerson
    print person

And on executing the program, you will get a different output:

  { personName = "Ned Effertz Sr."
  , personAddress = "Suite 158 1580 Schulist Mall, Schulistburgh, NY 15804-3392"

The above program can be even minimized like this:

main :: IO ()
main = do
    let settings = setNonDeterministic defaultFakerSettings
    person <- generateWithSettings settings fakePerson
    print person

Or even better:

main :: IO ()
main = do
    person <- generateNonDeterministic fakePerson
    print person



λ> import Faker.Address
λ> item <- generateNonDeterministic $ listOf 5 country
λ> item
["Ecuador","French Guiana","Faroe Islands","Canada","Armenia"]


λ> item <- generate $ oneof [country, fullAddress]
λ> item
"Suite 599 599 Brakus Flat, South Mason, MT 59962-6876"


λ> import qualified Faker.Address as AD
λ> item :: Text <- generate $ suchThat AD.country (\x -> (T.length x > 5))
λ> item
λ> item :: Text <- generate $ suchThat AD.country (\x -> (T.length x > 8))
λ> item
"French Guiana"

For seeing the full list of combinators, see the module documentation of Faker.Combinators.

Comparision with other libraries

There are two other libraries in the Hackage providing fake data:

The problem with both the above libraries is that the library covers only a very small amount of fake data source. I wanted to have an equivalent functionality with something like faker. Also, most of the combinators in this packages has been inspired (read as taken) from the fake library. Also, fakedata offers fairly good amount of support of different locales. Also since we rely on an external data source, we get free updates and high quality data source with little effort. Also, it's easier to extend the library with it's own data source if we want to do it that way.


Benjamin Curtis for his Ruby faker library from which the data source is taken from.

Icons made by Freepik from Flaticon.