# PyFlipper | Unoffical Flipper Zero Cli Wrapper Written In Python

**URL:** <https://onehack.st/t/pyflipper-unoffical-flipper-zero-cli-wrapper-written-in-python/224557>\
**Category:** Tools & Scripts\
**Tags:** tools, hacking, freebies\
**Created:** [September 30, 2022, 9:31pm UTC](https://onehack.st/t/pyflipper-unoffical-flipper-zero-cli-wrapper-written-in-python/224557 "2022-09-30T21:31:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueHacker](https://onehack.st/user_avatar/onehack.st/bluehacker/32/174721_2.png) [@BlueHacker](https://onehack.st/u/BlueHacker)\
**Post date:** [September 30, 2022, 9:31pm UTC](https://onehack.st/t/pyflipper-unoffical-flipper-zero-cli-wrapper-written-in-python/224557/1 "2022-09-30T21:31:42Z")

</div>

![image](https://onehack.st/uploads/default/original/3X/1/d/1dc875d93b3c4f3a75811526ee45fbe6c54b9f27.png)

# PyFlipper

Unoffical Flipper Zero cli wrapper written in Python

## Articles

- [How to hack a restaurant](https://medium.com/@nic_whr/how-to-hack-a-restaurant-5d394be105a9)

## Functions and characteristics:

- Flipper serial CLI wrapper
- Websocket client interface

## Setup instructions:

$ git clone [https://github.com/wh00hw/pyFlipper.git](https://github.com/wh00hw/pyFlipper.git) $ cd pyFlipper $ python3 -m venv venv $ source venv/bin/activate $ pip install -r requirements.txt

### Tested on:

- Python 3.8.10 on Linux 5.4.0 x86\_64
- Python 3.9.10 on Windows 10
- Python 3.10.5 on Android 12 (Termux + [OTGSerial2WebSocket](https://play.google.com/store/apps/details?id=com.wh00hw.serial2websocket) NO ROOT REQUIRED)

## Usage/Examples

### Connection

from pyflipper import PyFlipper #Local serial port flipper = PyFlipper(com=“/dev/ttyACM0”) #or #remote serial2websocket server flipper = PyFlipper(ws=“ws://192.168.1.5:1337”)

### Power

#Info info = flipper.power.info() #Poweroff flipper.power.off() #Reboot flipper.power.reboot() #Reboot in DFU mode flipper.power.reboot2dfu()

### Update/Backup

#Install update from .fuf file flipper.update.install(fuf\_file=“/ext/update.fuf”) #backup Flipper to .tar file flipper.update.backup(dest\_tar\_file=“/ext/backup.tar”) #restore Flipper from backup .tar file flipper.update.restore(bak\_tar\_file=“/ext/backup.tar”)

### Loader

#list installed apps apps = flipper.loader.list() #Open app flipper.loader.open(app\_name=“Clock”)

### Flipper Info

#Get flipper date date = flipper.date.date() #Get flipper timestamp timestamp = flipper.date.timestamp() #Get the processes dict list ps = flipper.ps.list() #Get device info dict device\_info = flipper.device\_info.info() #Get heap info dict heap = flipper.free.info() #Get free\_blocks string free\_blocks = flipper.free.blocks() #Get bluetooth info bt\_info = flipper.bt.info()

### Storage

#### Filesystem Info

#Get the storage filesystem info ext\_info = flipper.storage.info(fs=“/ext”)

#### Explorer

#Get the storage /ext dict ext\_list = flipper.storage.list(path=“/ext”) #Get the storage /ext tree dict ext\_tree = flipper.storage.tree(path=“/ext”) #Get file info file\_info = flipper.storage.stat(file=“/ext/foo/bar.txt”) #Make directory flipper.storage.mkdir(new\_dir=“/ext/foo”)

#### Files

#read file plain\_text = flipper.storage.read(file=“/ext/foo/bar.txt”) #remove file flipper.storage.remove(file=“/ext/foo/bar.txt”) #Copy file flipper.storage.copy(src=“/ext/foo/source.txt”, dest=“/ext/bar/destination.txt”) #rename file flipper.storage.rename(file=“/ext/foo/bar.txt”, new\_file=“/ext/foo/rab.txt”) #MD5 Hash file md5\_hash = flipper.storage.md5(file=“/ext/foo/bar.txt”) #Write file in one chunk file = “/ext/bar.txt” text = “”“There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don’t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn’t anything embarrassing hidden in the middle of text. “”” flipper.storage.write.file(file, text) #Write file using a listener file = “/ext/foo.txt” text\_one = “”“There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don’t look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn’t anything embarrassing hidden in the middle of text. “”” flipper.storage.write.start(file) time.sleep(2) flipper.storage.write.send(text\_one) text\_two = “”“All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. “”” flipper.storage.write.send(text\_two) time.sleep(3) #Don’t forget to stop flipper.storage.write.stop()

### LED/Backlight

#Set generic led on (r,b,g,bl) flipper.led.set(led=‘r’, value=255) #Set blue led off flipper.led.blue(value=0) #Set green led value flipper.led.green(value=175) #Set backlight on flipper.led.backlight\_on() #Set backlight off flipper.led.backlight\_off() #Turn off led flipper.led.off()

### Vibro

#Set vibro True or False flipper.vibro.set(True) #Set vibro on flipper.vibro.on() #Set vibro off flipper.vibro.off()

### GPIO

#Set gpio mode: 0 - input, 1 - output flipper.gpio.mode(pin\_name=PIN\_NAME, value=1) #Set gpio pin value: 0 - off, 1 - on flipper.gpio.set(pin\_name=PIN\_NAME, value=1) #read gpio pin value flipper.gpio.read(pin\_name=PIN\_NAME)

### MusicPlayer

#Play song in RTTTL format rttl\_song = “Littleroot Town - Pokemon:d=4,o=5,b=100:8c5,8f5,8g5,4a5,8p,8g5,8a5,8g5,8a5,8a#5,8p,4c6,8d6,8a5,8g5,8a5,8c#6,4d6,4e6,4d6,8a5,8g5,8f5,8e5,8f5,8a5,4d6,8d5,8e5,2f5,8c6,8a#5,8a#5,8a5,2f5,8d6,8a5,8a5,8g5,2f5,8p,8f5,8d5,8f5,8e5,4e5,8f5,8g5” #Play in loop flipper.music\_player.play(rtttl\_code=rttl\_song) #Stop loop flipper.music\_player.stop() #Play for 20 seconds flipper.music\_player.play(rtttl\_code=rttl\_song, duration=20) #Beep flipper.music\_player.beep() #Beep for 5 seconds flipper.music\_player.beep(duration=5)

### NFC

#Synchronous default timeout 5 seconds #Detect NFC nfc\_detected = flipper.nfc.detect() #emulate NFC flipper.nfc.emulate() #Activate field flipper.nfc.field()

### RFID

#Synchronous default timeout 5 seconds #read RFID rfid = flipper.rfid.read()

### SubGhz

#Transmit hex\_key N times(default count = 10) flipper.subghz.tx(hex\_key=“DEADBEEF”, frequency=433920000, count=5) #decode raw .sub file decoded = flipper.subghz.decode\_raw(sub\_file=“/ext/subghz/foo.sub”)

### Infrared

#Transmit hex\_address and hex\_command selecting a protocol flipper.ir.tx(protocol=“Samsung32”, hex\_address=“C000FFEE”, hex\_command=“DEADBEEF”) #Raw Transmit samples flipper.ir.tx\_raw(frequency=38000, duty\_cycle=0.33, samples=[1337, 8888, 3000, 5555]) #Synchronous default timeout 5 seconds #Receive tx r = flipper.ir.rx(timeout=10)

### IKEY

#read (default timeout 5 seconds) ikey = flipper.ikey.read() #Write (default timeout 5 seconds) flipper.ikey.write(key\_type=“Dallas”, key\_data=“DEADBEEFCOOOFFEE”) #emulate (default timeout 5 seconds) flipper.ikey.emulate(key\_type=“Dallas”, key\_data=“DEADBEEFCOOOFFEE”)

### Log

#Attach event logger (default timeout 10 seconds) logs = flipper.log.attach()

### Debug

#Activate debug mode flipper.debug.on() #Deactivate debug mode flipper.debug.off()

### Onewire

#search response = flipper.onewire.search()

### I2C

#Get response = flipper.i2c.get()

### Input

#Input dump dump = flipper.input.dump() #Send input flipper.input.send(“up”, “press”)

## Optimizations

Feel free to contribute in any way

- Queue Thread orchestrator
- Implement all the cli functions
- Async SubGhz Chat

## License

[MIT](https://choosealicense.com/licenses/mit/)

## Buy me a pint

**ZEC:** zs13zdde4mu5rj5yjm2kt6al5yxz2qjjjgxau9zaxs6np9ldxj65cepfyw55qvfp9v8cvd725f7tz7

**ETH:** 0xef3cF1Eb85382EdEEE10A2df2b348866a35C6A54

**BTC:** 15umRZXBzgUacwLVgpLPoa2gv7MyoTrKat

## Contacts

- **Discord** : white\_rabbit#4124
- **Twitter** : @nic\_whr
- **GPG** : 0x94EDEADC

## GitHub:

> **[GitHub - wh00hw/pyFlipper: Flipper Zero Python CLI Wrapper](https://github.com/wh00hw/pyFlipper)**
>
> Flipper Zero Python CLI Wrapper
