Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
S3 partition extraction in Python
import re
regex = r"(year|month|day|hour)=(\d+)"
test_str = "s3://bucket/datalake/year=2019/month=12/day=02/hour=06"
matches = re.finditer(regex, test_str)
partition = {match.group(1): int(match.group(2)) for match in matches}
print(partition)
# {'year': 2019, 'month': 12, 'day': 2, 'hour': 6}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment