Introduction and project setup
Python is a versatile, high-level programming language praised for its readability and extensive libraries, making it ideal for web development, data analysis, and automation. To manage project-specific dependencies and avoid conflicts, it’s best practice to use a virtual environment. You can create one in your project directory by running the terminal command python -m venv .venv, where .venv is the name of your environment folder. Once created, you must activate it. On Windows, use .venv\Scripts\activate, and on macOS or Linux, use source .venv/bin/activate. After activation, your command prompt will change to show the environment’s name, and any packages you install with pip will be isolated to that specific project. When you’re finished, simply type deactivate to return to your global Python context. This process keeps your projects tidy and reproducible.
Recommendation: codium for development
VSCodium, the open-source build of VS Code, is an excellent choice for Python development. After installing it, the first step is to add the official Python extension from the marketplace, which unlocks powerful features like IntelliSense (code completion), linting (error checking), and debugging. Open your project folder in Codium (File > Open Folder...). The editor will often automatically detect your virtual environment, but you can always manually select it by opening the Command Palette (Ctrl+Shift+P), searching for “Python: Select Interpreter”, and choosing the Python executable located inside your myenv folder. This correctly configures Codium to use your project’s isolated packages. You can then use the integrated terminal (Ctrl+ ) to run your scripts, install new packages with pip`, and manage version control with Git, all without leaving the editor. With the ability to set breakpoints and step through your code using the ‘Run and Debug’ panel, Codium provides a comprehensive and streamlined environment for building and testing your Python tool from start to finish.
Lets go
We highly recommend to use a unix based development environment. This is not only possible by using linux or macOS but also by installing Linux Subsystem for Windows. If you use a plan windows you might need to adapt in certain steps.
Generate venv
As shown above, we will use a venv. To do so we just execute the following commands.
python3 -m venv .venv
source .venv/bin/activate
Generate API code
As recommended in our documentation we use openapi-generator to generate the necessary code to interact with the API. This ensures safety and will break on critical errors as soon as possible.
mkdir api
openapi-generator-cli generate -i openapi.yaml -g python -o /api
cd api
pip install .
touch client.py
With your newly created client.py file you can now import the generated code and configure the client. You need the URL as well as your API-Key. This code has to be executed before issuing any api call.
import openapi_client as omniac
configuration = omniac.Configuration(
host = "https://api.omniac.de"
)
configuration.api_key["ApiKeyAuth"] = "YOUR_API_KEY_GOES_HERE"
Get tenant info
Now you can initialize a api instance of the TenantAPI. Use the gettenant function of your api_client to get information about your tenant.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.TenantApi(api_client)
api_instance = omniac.TenantApi(api_client)
try:
tenant = api_instance.get_tenant()
print(tenant)
except Exception as e:
print(f"Error: {e}")
Add profile to tenant
In order to start the monitoring of attributes and to receive alerts you need to configure a user for your tenant. After successfully creating the profile, you can start adding attributes.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
newProfile = omniac.ProfileCreateRequest(
name="test",
user_language="de",
)
try:
profile = api_instance.create_profile(newProfile)
print(profile.id)
api_response = api_instance.replace_attributes(profile.id, [
omniac.AttributeCreateRequest(
type="email",
value="test@example.com"
)
])
print(api_response)
except Exception as e:
print(f"Error: {e}")
Create multiple profiles as a batch
In addition to the option of creating individual profiles, omniac Business also offers the ability to create up to 500 profiles with attributes at the same time.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
profile_create_batch_request = [omniac.ProfileCreateBatchRequest(
name="Test1",
user_language="de",
attributes=[
omniac.AttributeCreateRequest(
type="email",
value="test@example.com"
)
]
)]
try:
profiles = api_instance.create_profiles(profile_create_batch_request)
print(profiles)
except Exception as e:
print(f"Error: {e}")
Get alerts
After waiting some minutes alerts will appear, if there are any leaks found. You can pull them by using the getprofile function with your profile.id. The two parameters after the profileID let you also return the users attributes (hashed and encrypted) as well as the alerts.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
try:
profile = api_instance.get_profile("profileID", True, True)
print(profile)
except Exception as e:
print(f"Error: {e}")
Provide a push alert endpoint
To get notified even faster, we provide a push api for new alerts. As soon as something is found, we will publish the alert into your system. This is done over a HTTP-call. The delivery will be marked as done on our side as soon as your api returns a 2xx http status code.
To use this feature, you need to contact us, so we can enable the feature for your tenant.