Skip to content

Conversation

techinz
Copy link

@techinz techinz commented Jun 26, 2025

Added loads() method to complement existing dumps()

I ran into a use case where I needed to deserialize fingerprints between sessions to keep them consistent and noticed there wasn't a loads() method to match dumps(). Not sure if that was intentional or just missed, but it feels like a natural pair.

This PR adds a loads() class method that reconstructs a Fingerprint object from JSON. A few people in the Issues tab have also asked how to handle this - hopefully this helps them too.

Code example:

from browserforge.fingerprints import Fingerprint, FingerprintGenerator

# 1. Generate and save the fingerprint

fingerprint_generator = FingerprintGenerator(browser='firefox')

# generate a fingerprint
original_fingerprint = fingerprint_generator.generate()

# dump it to a json string
fingerprint_dump = original_fingerprint.dumps()

# save the fingerprint dump to a file
with open('fingerprint_dump.json', 'w') as f:
    f.write(fingerprint_dump)

#
# ... do what you need with the fingerprint ...
#


# 2. Load the same fingerprint from the file

# for example, next run:

# load the fingerprint dump from the file
with open('fingerprint_dump.json', 'r') as f:
    fingerprint_data = f.read()

# load the fingerprint from the json string
loaded_fingerprint = Fingerprint.loads(fingerprint_data)

print('Fingeprints are equal:', original_fingerprint == loaded_fingerprint)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant