A simple Python client for interacting with the OneTimeSecret API, allowing you to securely share secrets with a customizable expiration time and region support.
Install via pip:
pip install onetimesecret
To use the OneTimeSecretCli client, import the class and initialize it with your OneTimeSecret API credentials. You can optionally specify a default region (e.g., "us" or "eu").
from onetimesecret import OneTimeSecretCli
# Replace with your OneTimeSecret credentials and preferred region
ONETIMESECRET_USER = "your_username"
ONETIMESECRET_KEY = "your_api_key"
REGION = "us" # Default region, can be "us" or "eu"
# Initialize the client
cli = OneTimeSecretCli(ONETIMESECRET_USER, ONETIMESECRET_KEY, REGION)
# Create a link for a secret message with a specified Time-to-Live (TTL)
link = cli.create_link("Your secret message here")
print("Secret link:", link)
cli = OneTimeSecretCli(ONETIMESECRET_USER, ONETIMESECRET_KEY, REGION)
- ONETIMESECRET_USER (str, optional): Your OneTimeSecret API username (usually your account email).
- ONETIMESECRET_KEY (str, optional): Your OneTimeSecret API key.
- REGION (str, optional): The region subdomain to use for API requests. Defaults to "us". Use "eu" for Europe. See Onetimesecret's website for the latest regions available.
# US region (default)
cli = OneTimeSecretCli("[email protected]", "api-key")
# EU region
cli = OneTimeSecretCli("[email protected]", "api-key", "eu")
# Anonymous Request (default region: US)
cli = OneTimeSecretCli()
create_link(secret, ttl=900)
- secret (str): The secret message you want to securely share.
- ttl (int, optional): The time-to-live for the secret in seconds (e.g., 900 for 15 minutes). Defaults to 900 seconds.
Running the example code will print a secure link that can be shared:
Secret link: https://us.onetimesecret.com/secret/xxxxxxxxxxx