Python bindings for faf-replay-parser
Project description
FAF Replay Parser
A fast library for parsing Supreme Commander Forged Alliance replay files.
Installation
Pre-built packages are available for Linux, MacOS, and Windows. You can install them with:
pip install faf-replay-parser
Documentation
Here are some examples of using the parser. Check help(fafreplay)
for more
details on available functions.
Gathering basic info
For the most basic uses there are a few special functions that should be
preferred over constructing a Parser
object. These do only one job, but they
do it very quickly.
Current functions:
body_offset
- Used for splitting replay data into header and body.body_ticks
- Used for extracting the game length.
Example
from datetime import timedelta
from fafreplay import body_offset, body_ticks
# Split replay data into header and body
offset = body_offset(data)
header_data, body_data = data[:offset], data[offset:]
# Get replay length in ticks
ticks = body_ticks(body_data)
print("Game length:", timedelta(milliseconds=ticks*100))
Using the Parser object
The Parser
object can be used to get fine grained control over how replay
commands are parsed. Generally it's a good idea to parse only the minimum
commands needed, as conversion back to python dictionaries is quite expensive.
from datetime import timedelta
from fafreplay import Parser, commands
parser = Parser(
# Skip all commands except the ones defined here
commands=[
commands.Advance, # For the tick counter
commands.VerifyChecksum, # For desync detection
],
# Throw away commands right after we parse them. Setting this to `True` will
# significantly increase the parse time.
save_commands=False,
limit=None,
stop_on_desync=False
)
# Or create a parser with default arguments (turn off save_commands though)
# parser = Parser(save_commands=False)
# Read replay to a `bytes` object
with open("12345.scfareplay", "rb") as f:
data = f.read()
# Parse to a python dictionary. Data must of type `bytes` or `bytearray`
replay = parser.parse(data)
print("Game time:", timedelta(milliseconds=replay["body"]["sim"]["tick"]*100))
if replay["body"]["sim"]["desync_ticks"]:
print("Replay desynced!")
Benchmark comparison
To see how much faster the basic functions can be, consider this simple example
done on replay 6176549
(an almost 50 minute long Seton's game).
>>> len(body_data)
5586339
>>> body_ticks(body_data)
28917
>>> parser = Parser(
... commands=[commands.Advance],
... save_commands=False
... )
>>> timeit.timeit("parser.parse_body(body_data)['sim']['tick']", globals=globals(), number=100)
1.4510237049980788
>>> timeit.timeit("body_ticks(body_data)", globals=globals(), number=100)
0.20173147800232982
In this case body_ticks
turned out to be more than 7x faster than using a
Parser
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for faf_replay_parser-0.5.2-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccecaa6d1684ee4fef997876d860f6f625ad5614aa8e9245e3f5d79e1af090e4 |
|
MD5 | 1a570c4321f7b37c80144546d6c6cd96 |
|
BLAKE2b-256 | 8e053bfbf3e3101d637923383c871f035cb345dd392319b374494d94851eefba |
Hashes for faf_replay_parser-0.5.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44d0f58ddf603b398950802fe13fbcab283fd0eb880c0549411372945ef85ca |
|
MD5 | 39a034d6232f620636787446e5475772 |
|
BLAKE2b-256 | 91ccb94b24a57f5cff8631a93f85d35d3c3bf4af74ab30d2bfa0c858b22a7c8b |
Hashes for faf_replay_parser-0.5.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6545375c5136dddee974f0ba063bbe8ad739ba234a602794dcc5502bde8adebc |
|
MD5 | 07d1ef27af59b6da495c434bce63180c |
|
BLAKE2b-256 | 5ba0deeadcab8a73abe5eb21093090e42ed9066ab3724c706dd64e3fa4c46bcc |
Hashes for faf_replay_parser-0.5.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbcbff05348024ae9c728e4c3fbc1b263dccfab9f72b81efcd40911160865358 |
|
MD5 | dba4b6315d3792db4b11f917d3e7400a |
|
BLAKE2b-256 | 97c713caa00ce5a65497c14c0fa1256bf68591cdec08206d334d4f2a1db79032 |
Hashes for faf_replay_parser-0.5.2-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9d2a7652e01c7bfdf5fc708ca288a837809173fbbbd2801e678f83a59b55b7c |
|
MD5 | fd300ed30d4af04fcf992c33a7795298 |
|
BLAKE2b-256 | 43feb067e227434b0dd39a0d687e0454aad40edb3a3afc8cc30b80d7d8b6fb83 |
Hashes for faf_replay_parser-0.5.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27ae95ba2b88489cfe259d865713427be05e9f54a75a879039a467168e879d94 |
|
MD5 | 4c33d02885ccfa831ca1105685b9a778 |
|
BLAKE2b-256 | eec84d3adc49fdf876b3b369cddb0e907605123ebc376519454ca53b463dead6 |
Hashes for faf_replay_parser-0.5.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58dd31c0fb1dae8b08e065c8cf2ca7a0a49b9fd95e25e569ddd0991643cb66ab |
|
MD5 | 7784a1b45a4c6c44ba5aa893098c4ca3 |
|
BLAKE2b-256 | 3e3030554adf5dfd3f9716eb8bd782669e907189d357522b4801954e42930a78 |
Hashes for faf_replay_parser-0.5.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30829fc10ae34754f0fefa6ad8d7a2ee1fd9830a2a5ff25d1dd1acdc7a5a170a |
|
MD5 | e58beef4525fd24c955a391fb15111d6 |
|
BLAKE2b-256 | 414c1be3d3bae3a245bd984922066e1c2d8ac3eace074a295361c073e782b727 |
Hashes for faf_replay_parser-0.5.2-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b000a1747f2d85ed8d947793b9efbdeded17042248b1f1354896f18ea5f95a1 |
|
MD5 | 31e374bd8e99a9badd728c65eb9d14a9 |
|
BLAKE2b-256 | 379bc199aa005789ae0eaf3f15e5c2f40b0456c73392070785e16912544e9ccd |
Hashes for faf_replay_parser-0.5.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958a86e6330cbf23efd5fa6c935f9d92e5f03a1740be9cae592c9e0e92b326c3 |
|
MD5 | 38a84731dd4c39990de7616cba496e20 |
|
BLAKE2b-256 | 762486e7c19178ac49b651276fe71954907552e1bee18d6f24786b37ade324e4 |
Hashes for faf_replay_parser-0.5.2-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af56ad669dfe9190d2dbc0ca6db3a11591ffe4ffd26a5a36e3d48566a42427e |
|
MD5 | 0ea060c982f6d65742e64c75cf339e95 |
|
BLAKE2b-256 | e1e832c6ce956683498470d3bc1d163e8f24ebc07bd393359b39afe9d0d0f151 |
Hashes for faf_replay_parser-0.5.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d776e24a8bd92076bc09a3715c4b4efced88cefd64f0993ab81135d001bd473 |
|
MD5 | 8449c37b4731b11221c57eda32996df9 |
|
BLAKE2b-256 | 52e8146b5676a50078c15d9db6c63ebd8e42084a37860c7b96c9e9e9759efdae |
Hashes for faf_replay_parser-0.5.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e054ea70e1ea63e9107a1666bbb0d45c75c2958af344f7b35d8bb8eaf75f1910 |
|
MD5 | 6aba756f86472ddd0636e51bd3b24e57 |
|
BLAKE2b-256 | 65020f970f1be622bebaef78b9a0e75e20ed72230fa43f30f4dd3d79c8455744 |
Hashes for faf_replay_parser-0.5.2-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b3318f26f72400ed54a8f65949a6dae7b9de3a04b2ffd847a6ad6491fc7fb5 |
|
MD5 | ad144f140a06c519ad238a49177542ae |
|
BLAKE2b-256 | aa779ec7bca64b93860d2d4c693b15f216026243f08482d54aa07c9e95dcdbe7 |
Hashes for faf_replay_parser-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd6dc31dcd16f92a9518851fb1248fb518a68404d6d60134470d0404556b5f81 |
|
MD5 | c0e74580edd3b595c7d9e6289440486a |
|
BLAKE2b-256 | 7692236734d0bcbef155dbfeee648f950257fc202292dab597e20154ec8bb34f |
Hashes for faf_replay_parser-0.5.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 568ac547dda121eeebf4fb45e8c53335f65338669b6db0d94162bc7e4d6559ea |
|
MD5 | 58b4018735af663f4e0025d0273491ed |
|
BLAKE2b-256 | fb113326003d5cb9d4a04281f72eb18af3c3a7517fbeaeeae25f79357b178902 |
Hashes for faf_replay_parser-0.5.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3aade7cf0f1a0f0d595da78dcf9c44816a2d637ecb19d69081b60b102ff9a0 |
|
MD5 | 74fda1dcd1d1785d1ea8f7587368d560 |
|
BLAKE2b-256 | ca500582eefbe3f3c59c73ed060e86bbae81d15f6722aa40790094fedb8e0e12 |
Hashes for faf_replay_parser-0.5.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f3dc8b8fe7cdc8ad0354bd459d849ad21c6c85d75c3b07e75fc1199afbaebdb |
|
MD5 | 0a22cd62f426755164efcaf71c4792a1 |
|
BLAKE2b-256 | 0331f344b2af288c0493dfd5a41cf30ee5e558773fcb7ff9380bcd3ab8b14336 |
Hashes for faf_replay_parser-0.5.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff2fd1a1c7c862f5a95c87c262000ffca489956178d68a6fcdea6b24ece69513 |
|
MD5 | e990f6044453f893a8e4c31c41617980 |
|
BLAKE2b-256 | cee5b8e58fe707f80e474ffad4866f7ccb6d7d1edd43a0de183393432a09e0f0 |
Hashes for faf_replay_parser-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7121144aa9cb6c32529e5d49c8af2e8a3cbadce755b0c271230a1c7362d5bfd8 |
|
MD5 | 9ae270894fd2419d59064e2a874df7c9 |
|
BLAKE2b-256 | 69160b780ea821975a0fb54b9870e8df3e7d2e1923e3560af94353e5acc61738 |
Hashes for faf_replay_parser-0.5.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87766b913f51281b5ce789c5bf5ce112331b3ae58bd7d12b540472cc92b51d2e |
|
MD5 | aa698da9d2625d0e094af9c8973d9c0d |
|
BLAKE2b-256 | ecd2edf57658ee451f7f89c4d73537052d9905ce432bb6b353934bdf43c4fd4a |
Hashes for faf_replay_parser-0.5.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad8889604a4597d13cf033452e21546d28ec23fd3b66c5b9251fbd9c8563ce2 |
|
MD5 | bf2b4b8ff9656573390b49ee59ec8bb7 |
|
BLAKE2b-256 | 7a6a9efeb10714eb45d4e1ad691e0eea9266ab203df36d7e666bef2b5e66527b |
Hashes for faf_replay_parser-0.5.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2851686cb0f132865761bc328462e9359a3d0ed204d2e013b8a050288b65d68 |
|
MD5 | 1f21c9a61e3e41eb7c87039a3462b64f |
|
BLAKE2b-256 | b9d4ea8196e3c767db50c54dc54738f50c8dc06f7fa291b5754e0b6b6a5fc676 |
Hashes for faf_replay_parser-0.5.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42807688f0f2022b71dfd30e23d76a67e37a332221b49eafc45355c31a569ba4 |
|
MD5 | c3bc9666b18a91d3ae15f1d3275db7a4 |
|
BLAKE2b-256 | 3c47fd0ded127681aa2d3e4525f5f11dc185d287dffdd1a2e26ad9e3deb4e2f8 |
Hashes for faf_replay_parser-0.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63fe33d0d20bb285fb928ea096e00089aff7af8a50e9dd157c975b353483d1d5 |
|
MD5 | dd532827965226a6a39b87f5f8ec5e7c |
|
BLAKE2b-256 | ff787a92f408a02a18c3d35e2f32074d20d2fded9987b78dcb5c510a89c43661 |
Hashes for faf_replay_parser-0.5.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5807baae1e4e29b0214cf8f39b9c52eeaa2e9880e6e5e9763fe0e8af6b8f549d |
|
MD5 | ac9ebe12583afea67624704cb2e0e8b9 |
|
BLAKE2b-256 | f5a94ab4eb0eeedc40f2200648e0d2fda33aed6ad58904e85877f998b4321d64 |
Hashes for faf_replay_parser-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca93999814a6bc6074e0a810611c177dfd9e5fde6ee6deeb166f2516e144f470 |
|
MD5 | b9373955036a1e81939ddd7cf7b84884 |
|
BLAKE2b-256 | 8780963706144cd452a40f80599be332237552e0c6a420c749a387b95a70edea |
Hashes for faf_replay_parser-0.5.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59ea614965caeb11f44a4cb8c576f1672430126c8f8591f8c8919bd37305e817 |
|
MD5 | 8056c004404191fcaf6b20b5e0b9b6f7 |
|
BLAKE2b-256 | d069d461db596dd2e4ad407ba6f111e1d58859dcca732440b0b99c7b11d9add4 |
Hashes for faf_replay_parser-0.5.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 680ff0bad5838e18ace9ecf2c6743aaedbfbe714649c0053bff4ff7f6deb074f |
|
MD5 | 6adda8bec9c08a474ada43f3e05e32b6 |
|
BLAKE2b-256 | 183ed4815d194bab6f37756e64a35a531c03bf3207cba4d1d0c6540993204933 |
Hashes for faf_replay_parser-0.5.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a898c3cf402c68de34e756e078e7e2298c97e572a432aac53d5fd61a2779bdb |
|
MD5 | bf33bd03decd466506ad6168adedc64f |
|
BLAKE2b-256 | 77367d3a7a1491ed0ae72d2492113e1512f980203df2d5911d9c6360d1479f97 |
Hashes for faf_replay_parser-0.5.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f39218a8d48d5e6113574b319d13394c485d4d8b65c1dea2862c8875616c453 |
|
MD5 | 1bf8a629c497b4e739db91a8f67855be |
|
BLAKE2b-256 | d6de968754271b6616333a0171581394e8f7c3742966b3d5ff1e7dcf02e6fc92 |
Hashes for faf_replay_parser-0.5.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebe3e1ad216e52267ec43ec1f9fdc648728c2dde350dcba4755941c6d224f988 |
|
MD5 | 1317034867fdc6ae02703641abe25a86 |
|
BLAKE2b-256 | be251c866044b68354b8e02adcf8c26fbc9e57782d708af282ddddb5ac486fdd |