Skip to main content

Generate random sentences through markov chains.

Project description

codecov travis build pypi version


Chattymarkov is a python module that lets you generate random sentences through a markov chain algorithm.

It is useful mostly for bots which are aimed at learning from user’s chat and generate totally w.t.f. answers.

The library can support multiple databases, especially redis which is quite suitable to store relevant information for markov chains.


pip install chattymarkov


From examples/

#!/usr/bin/env python3
from chattymarkov import ChattyMarkov

markov = ChattyMarkov("memory://")
markov.learn("My favorite animal is the crocodile")
markov.learn("The word animal is six letters long")

Here the markov instance learns two sentences (presumably gathered from a chat network such as IRC or Discord). What is interesting is that the ‘animal is’ sequence appears twice. So the generate() method, which returns a completely random result, may return an entirely built sentence which hasn’t been ever written by anyone:

$ ./
The word animal is the crocodile
$ ./memory
My favorite animal is six letters long

The more sentences, the funnier generated ones.

Supported databases

  • Redis (recommended): you can either provide a unix socket path (e.g. redis:///path/to/unix_socket.sock;db=0;password=foobar or an URL (e.g redis://user:password@localhost:6739/0). For the async version, either use redis_async:// or instantiate a ChattyMarkovAsync instance.
  • JSON: you can provide a path to a file that will be formated with JSON. Example: json:///path/to/file.json
  • Memory: in-memory database, just provide memory:// as a connect string. For the async version, use memory_async:// instead.


If you want to add some support to a database or redesign the library, please make a pull request so we can discuss about it.


  • Support other databases?

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

chattymarkov-1.3.0.tar.gz (8.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page