Skip to main content


A big bugfix is applied to this package due to the technique Python uses to import modules.

In previous versions, when brainfuck_to_function is called, it creates a module named _foo, which is imported. But Python also stores it into a cache, that means when you call brainfuck_to_function again, the new module would not be imported, which causes a function the same as the previous function is returned.

However, in this version and higher, a module with a random name is created instead, which fixed the bug.

This is a very fast brainfuck "compiler".

When used, it builds brainfuck code into Python extension modules, and imports it.

Requires:

  1. Python>=3.6
  2. C++ Compiler available
  3. pybind11

Running brainfuck

Use the 'brainfuck_to_function' function to convert brainfuck into function. It will take several seconds for the C++ compiler to build the module, but after build, you can call it anytime without building, which will be faster, and about 3x faster than directly using a brainfuck interpreter implemented in C++.

from fastbf import brainfuck_to_function
code='++++++++[>++++++++<-]>++++++++.>++++++++++++[>++++++++<-]>+++++.+++++++..+++.>++++[>++++++++<-]>.<<<<+++++++++++++++.>>.+++.------.--------.>>+.'
func=brainfuck_to_function(code)
func() # Hello World!

Freezing brainfuck into executables

fast-brainfuck is not supposed to be frozen into executables (e.g. using PyInstaller). But fortunately, you can use the 'dist_brainfuck' function to convert brainfuck into Python modules. You can write setup.py like this:

from fastbf import dist_brainfuck
code='++++++++[>++++++++<-]>++++++++.>++++++++++++[>++++++++<-]>+++++.+++++++..+++.>++++[>++++++++<-]>.<<<<+++++++++++++++.>>.+++.------.--------.>>+.'
dist_brainfuck(
    code,'hello'
)

Then run python setup.py build_ext --inplace, the files hello.py and hello.xxx.pyd (hello.xxx.so) will be created, you can now use

import hello
hello.run()

to run the brainfuck in your script (which CAN be frozen into executables).

Note that fast-brainfuck does NOT clean up the temporary files it creates. You have to manually delete them if you want.

fast-brainfuck can run on CPython or PyPy.

ImportError: xxx

If you encountered this error when using this package in PyPy in Windows, that means your username has non-ASCII characters. You can run

import os
os.environ['TMP']='C:\\Somedir'

before using fast-brainfuck to fix the error.

Note that moving the pointer to the left of the origin causes UNDEFINED BEHAVIOR in this version

Metadata

Release files for fast-brainfuck 3.0.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 fast-brainfuck 3.0.1
File Size Uploaded
fast-brainfuck-3.0.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fast-brainfuck 3.0.1
File Interpreter ABI Platform
fast_brainfuck-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.1 kB

Release files / fast-brainfuck-3.0.1.tar.gz

Download URL fast-brainfuck-3.0.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e96b7429699db147b0d441ad368bc46697b810d3a7c8840765c48c926e62832b
BLAKE2b-256 checksum
How to use checksums
c1999284949e1ead0da83f1561510c81d8823db99e18a1f22c6789893a042e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release files / fast_brainfuck-3.0.1-py3-none-any.whl

Download URL fast_brainfuck-3.0.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9819837bba8d0ffc61719906c60151421e4278ae2fcf0f54d622bbff0ef0413
BLAKE2b-256 checksum
How to use checksums
87716a690048335bcd49859ce51bb8a0db8a423feb8db5c1c625bcb3355f1627
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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