Skip to main content

brainfuck.py - seamless usage of Brainfuck in Python code

brainfuck.py compiles Brainfuck programs to Python AST, enabling the integration of industial-strength Brainfuck programs with Python code. Example:

>>> import brainfuck
>>> hello = brainfuck.to_function("""
    ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>
    .>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
    """)
>>> hello()
'Hello World!\n'

For convenience, an import hook is also provided:

>>> brainfuck.install_import_hook()
>>> # Note: programs is a python package (with __init__.py
    # and a brainfuck file named rot13.bf)
>>> from programs import rot13  
>>> rot13.rot13("brainfuck")
'oenvashpx'
>>> # The module can also be called directly
>>> rot13("foobar")
'sbbone'

Installation

$ pip install python-brainfuck

OR

$ git clone git@github.com:koirikivi/brainfuck.git
$ cd brainfuck
$ python setup.py install

OR just copy brainfuck.py somewhere in your PYTHONPATH.

Platform support

Latest versions of Python 2, 3 and PyPy are supported and tested. Other Python versions that have support for the ast module should work too, but are not tested.

Unit tests

Run tests with $ python test_brainfuck.py

TODO

  • Optimizations for the brainfuck-generated AST (this is a big one!)
  • More tests
  • Running tests with tox
  • Python AST to brainfuck compilation (may take some time)

License

MIT (programs in the programs-directory may be licensed differently)

Metadata

Release files for python-brainfuck 0.9.1

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

Source distribution (sdist)

Source distribution for python-brainfuck 0.9.1
File Size Uploaded
python-brainfuck-0.9.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-brainfuck 0.9.1
File Interpreter ABI Platform
python_brainfuck-0.9.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.8 kB

Release files / python-brainfuck-0.9.1.tar.gz

Download URL python-brainfuck-0.9.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a39d7c48765289a71f4d1a2a773194bf766f3c0287db98650e8d8510f3c2332b
BLAKE2b-256 checksum
How to use checksums
f71bfbe21b1760549b673815233729685638b16f6b967c6edbf29a1c7f168158
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

Release files / python_brainfuck-0.9.1-py2.py3-none-any.whl

Download URL python_brainfuck-0.9.1-py2.py3-none-any.whl
Size 5.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
36696e6fa571fbd93d72c4106a5d93a5df36d6e47fba58804efd333af7882f50
BLAKE2b-256 checksum
How to use checksums
8c3d962805f509a2277e2a3a2221a8249b22fe90e8e6d5dce965a9be8cf541e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.0.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

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