{"id":16735939,"url":"https://github.com/tarb/betfair_data","last_synced_at":"2025-03-17T01:31:53.782Z","repository":{"id":42431672,"uuid":"291533731","full_name":"tarb/betfair_data","owner":"tarb","description":"Fast Python Betfair historical data file parser","archived":false,"fork":false,"pushed_at":"2022-05-05T03:49:36.000Z","size":24073,"stargazers_count":42,"open_issues_count":12,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-27T16:21:36.476Z","etag":null,"topics":["betfair","betfair-data","python","rust"],"latest_commit_sha":null,"homepage":"https://betfair-datascientists.github.io/tutorials/jsonToCsvRevisited/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tarb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-30T19:02:08.000Z","updated_at":"2025-02-25T11:59:54.000Z","dependencies_parsed_at":"2022-07-19T00:02:02.963Z","dependency_job_id":null,"html_url":"https://github.com/tarb/betfair_data","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarb%2Fbetfair_data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarb%2Fbetfair_data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarb%2Fbetfair_data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarb%2Fbetfair_data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarb","download_url":"https://codeload.github.com/tarb/betfair_data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["betfair","betfair-data","python","rust"],"created_at":"2024-10-13T00:07:47.826Z","updated_at":"2025-03-17T01:31:51.057Z","avatar_url":"https://github.com/tarb.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Betfair Data\n\nBetfair Data is a very fast, Rust based, Betfair historical data parsing library for python. It supports both the official [Betfair's historic data](https://historicdata.betfair.com/#/home) and self recorded stream files. \n\n## Installation\n\n```\npip install betfair_data\n```\n\nNote: requires Python \u003e= 3.7.\n\n## Example\n\n```python\nimport betfair_data as bfd\n\npaths = [\n    \"data/2021_12_DecRacingAUPro.tar\",\n    \"data/2021_10_OctRacingAUPro.tar\",\n    \"data/2021_11_NovRacingAUPro.tar\",\n]\n\nmarket_count = 0\nupdate_count = 0\n\nfor file in bfd.Files(paths):\n    market_count += 1\n\n    for market in file:\n        update_count += 1\n\n    print(f\"Markets {market_count} Updates {update_count}\", end='\\r')\nprint(f\"Markets {market_count} Updates {update_count}\")\n\n```\n\n## Loading Files\n\nYou can read in files quickly in a worker thread using the provided ```Files``` utility. It supports reading in bz2, gzip or uncompressed (.json) stream files or .tar or .zip archives containing such files. \n```python\n\npaths = [\n    \"data/2021_10_OctRacingAUPro.tar\",\n    \"data/2021_11_NovRacingAUPro.zip\",\n    \"data/self_recorded_market.gz\",\n    \"data/uncompressed_market.json\",\n\n]\nfiles = bfd.Files(paths)\n```\nOr you can use the glob library to find and select all the paths automatically. \n\n```python\nimport glob\n\npaths = glob.glob(\"data/betfair_official/*.tar\") + glob.glob(\"data/self_recorded/*.gz\")\nfiles = bfd.Files(paths)\n```\n\nYou can also load the file through any other means and pass the raw bytes and name into the File object constructor.\n\n```python\n# generator to read in files\ndef load_files(paths: str):\n    for path in glob.glob(paths, recursive=True):\n        with open(path, \"rb\") as file:\n            yield bfd.File(path, file.read())\n\nfor file in load_files(\"markets/*.json\"):\n    for market in file:\n        pass\n```\n\n## Benchmarks\n\nRunning over 3 months of Australian racing data on a 2021 M1 Macbook Pro.\n\n| betfair_data (mutable) | betfair_data (immutable/bflw compat) | betfairlightweight lightweight=True | betfairlightweight lightweight=False|\n| -----------------------|--------------------------------------|-------------------------------------|-------------------------------------|\n| 5m 12sec               | 6m 50sec                             | 1hour 1min 45sec                    | 3hours 46mins 39sec                 |\n| ~70 markets/sec        | ~53.5 markets/sec                    | ~6 markets/sec                      | ~1.62 markets/sec                   |\n| ~534,200 updates/sec   | ~406,500 updates/sec                 | ~45,500 updates/sec                 | ~12,250 updates/sec                 |\n\n\n## Types\nIDE's should automatically detect the types and provide checking and auto complete. See the [pyi stub file](betfair_data/betfair_data.pyi) for a comprehensive view of the types and method available.\n\n\n## Betfairlightweight\nWe also support a format that is a drop in replacement for ```betfairlightweight``` objects. We have rigorously tested it against betfairlightweight to ensure a complete match of its structure, any differences should be submitted as issues with the corresponding differences and the data used to create them.\n```py\nfrom betfair_data import bflw\n\nfiles = bflw.Files(paths)\n```\n\n```py\nfrom betfair_data import bflw\n\nfile_bytes = ...\nfile = bflw.File(\"file_name\", file_bytes)\n```\n\n## Logging\n\nLogging can be enabled and warnings are emitted for IO and JSON errors.\n\n```python\nimport logging\n\nlogging.basicConfig(level=logging.WARN, format='%(levelname)s %(name)s %(message)s')\n```\nExample logged errors\n\n```log\nWARNING betfair_data file: data/2021_10_OctRacingAUPro.tar/PRO/2021/Oct/4/30970292/1.188542184.bz2 err: (JSON Parse Error) expected value at line 1480 column 1\nWARNING betfair_data file: data/2021_10_OctRacingAUPro.tar/PRO/2021/Oct/8/30985584/1.188739324.bz2 err: (JSON Parse Error) expected `:` at line 1 column 909\nWARNING betfair_data file: data/2021_10_OctRacingAUPro.tar/PRO/2021/Oct/8/30985584/1.188739325.bz2 err: (JSON Parse Error) expected `:` at line 1 column 904\nWARNING betfair_data file: data/2021_10_OctRacingAUPro.tar/PRO/2021/Oct/15/31001342/1.189124831.bz2 err: (JSON Parse Error) expected value at line 1335 column 1\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarb%2Fbetfair_data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarb%2Fbetfair_data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarb%2Fbetfair_data/lists"}