Skip to main content

codecov travis build pypi version

Description

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.

Installation

pip install chattymarkov

Examples

From examples/memory.py

#!/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")
print(markov.generate())

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:

$ ./memory.py
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 a host:port (e.g redis://localhost:6739;db=0). Extra parameters are separated by semi-colons after the unix socket path / host:port descriptor. For the async version, use redis_async:// instead.

  • 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.

Contribute

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.

Todo

  • Support other databases?

Metadata

Release files for chattymarkov 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chattymarkov 1.2.3
File Size Uploaded
chattymarkov-1.2.3.tar.gz 7.3 kB Details

Release files / chattymarkov-1.2.3.tar.gz

Download URL chattymarkov-1.2.3.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0fbde5b12d2d6944328ed4f065db63437794e0591e7a086f8f86ad0dff9f78b1
BLAKE2b-256 checksum
How to use checksums
fabffe3435119b45cbcc8a4ae6dabd59fdd408e12d62b29ffb2a78e8573f6997
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release history Release notifications | RSS feed

1.3.0

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

This release

1.2.3 This release

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.0.4

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page