Overview
In this quickstart, you’ll add Fingerprint to a Python backend using the web framework FastAPI to prevent fraudulent account creation. The example use case we’ll use for this quickstart is stopping new account fraud, where attackers create multiple fake accounts to abuse promotions, exploit systems, or evade bans. However, the steps you’ll follow apply to most use cases. You can flag and block suspicious users by identifying the device behind each sign-up attempt, login, or transaction. In this quickstart, you’ll learn how to:- Set up a FastAPI server with a Fingerprint integration
- Retrieve visitor identification data using the Server API
- Block bots and suspicious devices
- Prevent multiple signups from the same device
Estimated time: < 10 minutes
Prerequisites
Before you begin, make sure you have the following:- A completed front-end or mobile Fingerprint implementation (See our quickstarts)
- Python (3.8 or later) installed
- Your favorite code editor
- Basic knowledge of Python
1. Get your secret API key
If you’re ready:
- Sign in and go to the API keys page in the Fingerprint dashboard.
- Create a new secret API key.
- Copy it somewhere safe so you can use it to retrieve full visitor identification data from the Server API.
2. Set up your project
To get started, set up a basic server. If you already have a project you want to use, you can skip to the next section.- Create a new Python project and set up the virtual environment:
Terminal
- Create a
requirements.txtfile with the dependencies:
requirements.txt
- Install dependencies from the requirements.txt file:
Terminal
- Create a new file called
server.pyand add a basic FastAPI server setup:
server.py
/api/create-account route should match what you have set up in your front-end implementation where you are sending the Fingerprint requestId to your server. Your server will receive the initial identification information from identifying a visitor on the front end and use it to get the full visitor data on the back end.
3. Initialize Fingerprint and retrieve visitor data
Now you’ll configure the Fingerprint Server SDK using your secret API key and use it to fetch detailed visitor data for each signup attempt. When making the initial visitor identification request in the front end, you received arequestId. This ID is unique to each identification event. Your server can then use the Fingerprint Events API and retrieve the complete identification data, including the trusted visitor ID and other actionable insights like whether they are using a VPN or are a bot.
- Create a
.envfile in your project root and add your secret API key:
.env
- At the top of your
server.pyfile, import and initialize the fingerprint SDK:
server.py
- In your
/api/create-accountroute, use therequestIdyou are sending from the front end to fetch the full visitor identification details:
server.py
requestId the Fingerprint server client will retrieve the full data for the visitor identification request. The returned object will contain the visitor ID, IP address, device and browser details, and Smart Signals like bot detection, incognito mode detection, and detections for VPN or virtual machine use.
You can see a full example of the event structure, and test it with your own device, in our demo playground.
For additional checks to ensure the validity of the data coming from your front end view how to protect from client-side tampering and replay attacks in our documentation.
4. Block bots and suspicious devices
This optional step uses the Bot Detection Smart Signal which is available only
on paid plans.
event object includes the Bot Detection Smart Signal that flags automated activity, making it easy to reject bot traffic.
- Continuing in your
/api/create-accountroute, check the bot signal returned in theeventobject:
server.py
good for known bots like search engines, bad for automation tools, headless browsers, or other signs of automation, and notDetected when no bot activity is found. You can also layer in other Smart Signals to catch more suspicious devices. For example, you can use Fingerprint’s Suspect Score to determine when to add additional friction to create an account.
5. Prevent multiple signups from the same device
To catch repeated signups from the same device, you can use thevisitorId from the Fingerprint identification event. By saving this ID alongside each created account, you can easily detect and block duplicate signups. We’ll be using a simple database to demonstrate how this works with SQLite.
- At the top of your
server.pyfile, import and initialize the database:
server.py
- In your
/api/create-accountroute handler, after getting the event, extract thevisitorId:
server.py
- Check if this device has already created an account; if yes, block the account creation:
server.py
This is a minimal example to show how to use the Fingerprint SDK. In a real
application, make sure to implement proper security practices, especially
around password handling and storage.
6. Test your implementation
Now that everything is set up, you can test the full flow using your existing front end.Test the implementation
- Start your FastAPI server:
Terminal
- In your front end, trigger a sign-up request that sends the
requestId,username, andpasswordto your/api/create-accountendpoint. To see the reply messages make sure to parse and display or console log the response from your server. - Within your front end, input a username and password to create a user. Then try to create another user and see that the second attempt will be rejected.
- Bonus: Try creating an account using a headless browser.