Pactole Library Overview
Pactole is a Python library that fetches, caches, and queries lottery draw results. It models lottery combinations, draws, and winning ranks, and provides helpers to search historical records by combination or by winning rank.
Core concepts
- Lottery classes:
EuroMillionsandEuroDreamsprovide a ready-to-use interface. - Providers:
BaseProviderorchestrates fetching archives, parsing them, and caching results. - Parsers and resolvers:
BaseParserconverts raw archive rows intoDrawRecordinstances;BaseResolverdiscovers archive URLs. - Combinations:
LotteryCombinationand its subclasses model draw numbers and ranks.
Quick start
from pactole import EuroMillions
lottery = EuroMillions()
# Build a combination using the lottery factory.
played = lottery.get_combination(numbers=[5, 12, 23, 34, 45], stars=[2, 9])
# Get cached records (auto-refreshes if needed).
records = list(lottery.get_records())
# Find a specific combination in past draws.
matches = list(lottery.find_records(played))
# Inspect cache-backed history helpers.
total_draws = lottery.count()
sample = lottery.dump()[:1]
# Compute draw dates
last_draw = lottery.get_last_draw_date()
next_draw = lottery.get_next_draw_date()
# Generate random combinations with the same game rules.
random_tickets = lottery.generate(n=3)
See detailed usage guides:
Provider customization
If you want to pull data from a different source, implement a resolver and parser:
from pactole.data import BaseParser, BaseProvider, BaseResolver, DrawRecord
from pactole.combinations import EuroMillionsCombination
from pactole.lottery import BaseLottery
from pactole.utils import Weekday
class MyResolver(BaseResolver):
def _load_cache(self) -> dict[str, str]:
return {"archive.csv": "https://local.test/archives/evm.csv"}
class MyParser(BaseParser):
def __call__(self, data: dict) -> DrawRecord:
# Convert raw fields to a DrawRecord
raise NotImplementedError
provider = BaseProvider(
resolver=MyResolver(),
parser=MyParser(),
draw_days=[Weekday.TUESDAY, Weekday.FRIDAY],
combination_factory=EuroMillionsCombination,
cache_name="euromillions-custom",
)
lottery = BaseLottery(provider)
records = list(lottery.get_records())
Caching behavior
- Archives are downloaded and parsed into cached CSV files under the OS cache directory.
- The cache is refreshed when a new draw is expected or when
force=Trueis used.
Environment variables
Defaults can be overridden for built-in lotteries:
PACTOLE_CACHE_ROOTEUROMILLIONS_PROVIDER_CLASSEUROMILLIONS_DRAW_DAYSEUROMILLIONS_DRAW_DAY_REFRESH_TIMEEUROMILLIONS_CACHE_NAMEEUROMILLIONS_ARCHIVES_PAGEEURODREAMS_PROVIDER_CLASSEURODREAMS_DRAW_DAYSEURODREAMS_DRAW_DAY_REFRESH_TIMEEURODREAMS_CACHE_NAMEEURODREAMS_ARCHIVES_PAGE
Notes
- This library focuses on draw history management and combination-based queries.
- For custom lotteries, plug in your own resolver/parser pair and combination class.