Python bindings for faf-replay-parser
Project description
FAF Replay Parser
A fast library for parsing Supreme Commander Forged Alliance replay files.
Installation
Currently, pre-built packages are only available for Linux. 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.1.post0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7049ff79044d3e8cc914e57a81a44b62c20b0e8966630146e959a2d8ece86f60 |
|
MD5 | 628f98ccfbc3fd0973e41e4e5739d645 |
|
BLAKE2b-256 | 49ce30a22885bd9948390f0e37c2380917d249c765be396f834069ecb52b34ee |
Hashes for faf_replay_parser-0.5.1.post0-pp37-pypy37_pp73-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee5145a84d99940687b8d216e97eaa625d760920b9f0189592f28c7da71e14e |
|
MD5 | a1afac7051cd2b9b3ac9915d5b97f51a |
|
BLAKE2b-256 | 8951b9a9adb96b75fc8d1910d641f331bf05c5d7283068b63e23804a4ac096ee |
Hashes for faf_replay_parser-0.5.1.post0-pp37-pypy37_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f12157d00883df33694876a9af231e8de322ef38aabedc23a629236af2c856a |
|
MD5 | a84759cb04fbe3df654bc116e5025f0d |
|
BLAKE2b-256 | b1bc49d0af3b52515f2e5cf5dc1e5ebb70aa9751cbb43f97d5b308d8e3d10216 |
Hashes for faf_replay_parser-0.5.1.post0-pp37-pypy37_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897e606123c86e74e04314655db61725d2823e54d310f2c64043e27b238d8c8b |
|
MD5 | 7781d3520772835bca535b7087c352e9 |
|
BLAKE2b-256 | 9a1fa4dba87a13862b087bfbc0b4b5d1ceb4bbc6718eb7161ec1f71e2937466e |
Hashes for faf_replay_parser-0.5.1.post0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb36054a8b68fe96ffd712d0791a2836fb054943484db4c42fe23d2de3d8787 |
|
MD5 | 9be0195da959386c941bd7b6d6cc6828 |
|
BLAKE2b-256 | af005aafd724520ccf8dd899cc5bcb548dbfa5fae7fbd1cfe084a13808deb961 |
Hashes for faf_replay_parser-0.5.1.post0-pp36-pypy36_pp73-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0874950cd2b2bbd54c997eed4423e7d63c1a60c3e704beacba32d5d42b73176d |
|
MD5 | 23770654800a2350ec6485883922466e |
|
BLAKE2b-256 | 0900dfa043ce27b7995df875b39443b65735eb6064a77d1612a0253e2008a7da |
Hashes for faf_replay_parser-0.5.1.post0-pp36-pypy36_pp73-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8faed12a242cd9a7eaf7639b7f5efb5874c15b075724221c4308f391725ae0e1 |
|
MD5 | dfa9ef063ea38e33c13b2b6f64310080 |
|
BLAKE2b-256 | 4684e97c55cb3858bad6d6ed246243ff707511c4ab36c6955a23eebde8b66cc4 |
Hashes for faf_replay_parser-0.5.1.post0-pp36-pypy36_pp73-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0a9606bbec5a892c9e7ff627d6b16fb9e8aa0633d89b41d640d4ac3bac29668 |
|
MD5 | 59b4d64d7fa772154d4ebdbebdc6c05a |
|
BLAKE2b-256 | 8ec94e9cab7e1a166e240f4154a69b9f56259d6ea1810f8c3699d7f3952f5d4a |
Hashes for faf_replay_parser-0.5.1.post0-pp36-pypy36_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b38500cd41c617343bb86741407276338607c06c9598414ecf29049caf9a3ee |
|
MD5 | 6c4541a2e227b69ef655d25b096d8175 |
|
BLAKE2b-256 | 3b4ba09cbe378558b7030f3b9a4e1b9cbffef62ee8903cf7f282616447ee8cfd |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce3bde50183bad72813e2253756fedd552ccf51abcfaed46537186c0836a6249 |
|
MD5 | 9b4c578944227151773f432b69be2667 |
|
BLAKE2b-256 | e1a4285ef50c2100a53959f95018b3a4f9816e522aea98a7887002818399105f |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c649f5017342a5e41c4474e8f66a52ce4239b8651d0ad8bdf138d1f21fcf595 |
|
MD5 | 22e758b7e185859fb401afec2e0236af |
|
BLAKE2b-256 | a2e6a4ab9c6ce5d631ec08eac9455340d184fb1dd418840ba3eb7ff991d7030a |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18cc39bc09afd9b4a1c41b781621bef69fedf522222ff5a887c80edfd3fe46cc |
|
MD5 | d169c7280d3fc6372a8f3173f48351ba |
|
BLAKE2b-256 | db2d5f30a9ab8dd8e87d17eb594eed9e1367ed2dd122697f5ec0e695e969bd65 |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832106cdff778857c36466339f911408e425121017a6db0cb208382642cc8ef6 |
|
MD5 | 460522f0b5f98bdb7fb6c9e83ab56871 |
|
BLAKE2b-256 | 1b9bd93f049d9e39dbe548c89d2a3305ce1be3b14368cc26de62cc3ac2ecd1e5 |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 852a16ec0f00e18adbb3051cbb862e2c91cbb8b4b40efc5e0ed12a9610c6420f |
|
MD5 | 543fdc95ac09d4635b2e753523b12476 |
|
BLAKE2b-256 | 9adb3fe0b170d92d8902828ae561d6f5af3864464c158b0f5ecdbb909531af08 |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 949c66674d1b4bdcdac07a83aa7ceb5e5a7b7ec4cf9b51b8e7b6f62c068c6006 |
|
MD5 | 1fe80b3a4b0b529a5dd0d8e1c7ee20c2 |
|
BLAKE2b-256 | 5e5da8fc4bc723c9a9a69335e35e761e6619e6c0f3cc64c4128b467899b7eb6a |
Hashes for faf_replay_parser-0.5.1.post0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66ad5b4b1eb5f0505891f344b55f697025e36f8b731a7ae8b63eb81e9490a76f |
|
MD5 | 1dc6f76a76f63b8a9991faa513f18958 |
|
BLAKE2b-256 | 8ba8f41a4b7f50637c66eb5c6f39725f86661ec5d22654bc0c3b330c54dbc906 |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccfe326d5234c55ae463fb38d458632b5df2a48e41007134c4655414c0363b86 |
|
MD5 | 013fc8ed0154419734d5101655916614 |
|
BLAKE2b-256 | 1d02fd25d8824cd947f81e1e7512c62f8c6eaf81d92876a184999e4bb067fb0c |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f9998cba26179c3a69e459c93470a0d172bc53d7e7d4dd8dede822a74fbbd73 |
|
MD5 | e0f95912853b977ee30500c209fd9f92 |
|
BLAKE2b-256 | a8a1db84d6ea47ee3ab862271a466956afd051a434f58d4baac5d18e943aebd0 |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f79af2f7f84f0ab330ad23eddc322259de321cc188ad01328fb652f7bcc258c7 |
|
MD5 | 456d3902185a089cdb2d33a129445d6a |
|
BLAKE2b-256 | 4de302f1c099a4052a575c73f7215ef34a2d72be6b81e51823d882b136c882f3 |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61f4bce210b67cde8a25e6abf3b0d9b4f9c805fa359922631ce65061e09675f2 |
|
MD5 | 76e2eb5b416c7d854571c9b6c73ec363 |
|
BLAKE2b-256 | c151b676652c49fc637f7e2e637df13289ce6327013d532417b9f8327a70f3bc |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdb5a9cd5a86fbc6aa2c532fcd31ef521e39d576ab18e13a930c5265b1b0e000 |
|
MD5 | d87af92e80f19c171a7ba1a47eeed946 |
|
BLAKE2b-256 | 15afa41a4c938889e5aba9c5e125dff5a3587dc4b653bc5b03c66b2f69fabe7b |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d13ef0c9d00a06786e7ee70f5beac135b8e08f103d28b846732cc18c11a764e3 |
|
MD5 | b34ba82ae39ee013d7d28d76ceb66b0f |
|
BLAKE2b-256 | 5287c1be85010719169d33d687e02facf1c24a51909b6a8147acbec70bf1045c |
Hashes for faf_replay_parser-0.5.1.post0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab84983a6def27e44ac67c71a41be2bd4e08c4abf39632ea775b3b18dbbe22fb |
|
MD5 | 5c59897b38ed01515c50c3fa5f1a9ec2 |
|
BLAKE2b-256 | 6029246c2ede2e40af6654883a93c17f4cf0fb350f583f270d6832efbf937b20 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d31b54d17d24b9791c017636b98ba24b096646cba8b8f05f298cdf570fe517e |
|
MD5 | 614e492906345a391b7d80f89fe3c181 |
|
BLAKE2b-256 | f6a87b5c9eff3db1cacd2fd7d911e9af02c5e28be7c565fd87d4cab3c663bda9 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6741adb5c238713d64b8b95926f08f3bfe8148888dae31c8cd89c419aa888cc2 |
|
MD5 | cae16e16c616be5cde860ca07286777c |
|
BLAKE2b-256 | 8397cfc459258deb33367aeb7d02162e8e872a6704b62607427b5d9779c1ef95 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509b252331b3304c73ea0b4f763ff7e504153284eb251daa5baa74f9d6b79b8b |
|
MD5 | d6b72883662861a1735124934713e6ed |
|
BLAKE2b-256 | 47836e8bc8064ba28a5966275487af6e1f21f61df3d786464d78d1d7534078f8 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afb203b703765cafb3a95fe6d834bb1e53def4f0c0096a3ca7d0302b509a07fc |
|
MD5 | dc9a02a77e500037374c38db4a97c7c4 |
|
BLAKE2b-256 | 8a85990079bb81dbc5018383eb13805d418c527440947b90a23472348fcab3db |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04649956ee663c17ecc0862ccaa57d0387104519497273e79c524fcfb121e84f |
|
MD5 | 42346c5261eb2fd376a33f5d6a41852b |
|
BLAKE2b-256 | e28a9ed15bb85d3ecdc4f8079c89b2061bf2576dcc631a52f5e6db0aec0e99f9 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 578657f71b7070224dcabe2ae76b71d36e37bea4ad6548a76ba5f7f2596f3248 |
|
MD5 | b5624b8cb0977cbc0bcde9fa30239f3a |
|
BLAKE2b-256 | 3ae37544a4d0982e95ea8d88755f6ff7c83d2d9370c0ee9a00ce77c03668a409 |
Hashes for faf_replay_parser-0.5.1.post0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e6de7009a454d24e030c6481d9d01c7c5dec9e2de05c89efddd2d2fdd4218f1 |
|
MD5 | 5bdd6a5adac5ed9c52eb499f29a504fc |
|
BLAKE2b-256 | 6403f16fe6999b85f65612da23e4a7cc7277d8d53de42346f748dbddd481f469 |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdc6aca9ce9ae1abf4e55c9f3daee22e76088b58a6d3f78f4e5209e5e6fd76ae |
|
MD5 | b9cf7e8ded36422037af01ad40346c70 |
|
BLAKE2b-256 | 19bf9a43ef57646543b28e6d661a8b8fedc30d2d1575baed334f79fa0e6518bb |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2509c0fbe699acfb0d0f28271cef6ecb8103197c8bc78440062df97c40e6438 |
|
MD5 | 8cadba6af66bd1418e5c8077864355ac |
|
BLAKE2b-256 | f4fc03874fb7b0caba9229f780d1df379d2fa845598dbf3102c3cd1fc984c2b2 |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e6786cfa218dea6a1556ff6719d65e903036c1d19d0c0ccbc8169e384720bf |
|
MD5 | bfbf2ec2a40e383bb03382d54a15be35 |
|
BLAKE2b-256 | 9687ce483ba6fd73ffec10ed5b29991cc1459307d1e0e1d6b7882bf852a3c273 |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14b0518855f4e5481dde0254fca8cf4e769c37d9c1be025bd8c1bce3cce845f3 |
|
MD5 | 3bca663e43f3f135e109de087a45959e |
|
BLAKE2b-256 | 8035516ef45f9439de78271b170441037e8857f572b36cf4ecd72d04f2f0840f |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aee9e05e737595363839a974baff7dddb131ac606fc156e0ad6dc00cbc525e4c |
|
MD5 | 8ec2997f89a45138650eb64ea4b90f87 |
|
BLAKE2b-256 | 5d8fc6e4bdcee60e5444df89c788f50d37f7c8d6a4af7795f8aa99697203aadc |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2043611ba4a1dec4be33280724c02db89efbe6ee66702ba81550a70d56050085 |
|
MD5 | 57cb78f745c814eb2effe1ec72713e76 |
|
BLAKE2b-256 | ac2d1f6f8add44a11ab898d3db9444b3bb8347fca66d1dc6eedc5fd99dbc31c9 |
Hashes for faf_replay_parser-0.5.1.post0-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93fbd9810805e0e52d67970d99e20739feee34ce21b1221607d216b03cb495b8 |
|
MD5 | 3a1472d25e4270dc0f82ceb64017b2c5 |
|
BLAKE2b-256 | c2b1f07bdbdfcb08875f0575d8649a985613470520081c87210149638c74f3cc |