Python client for CheatLab API - Quick command reference storage
Project description
CheatLab Python Client
Python client library for the CheatLab API - Quick command reference storage and retrieval system.
Installation
pip install cheatlab
Quick Start
from cheatlab import Cheat
# Initialize client with your credentials
cheat = Cheat("your_username", "your_auth_key")
# Create a message
cheat.post("Hello World", key="greeting")
# Retrieve it
print(cheat.get("greeting")) # Output: Hello World
# Delete it
cheat.delete("greeting")
Authentication
Get your credentials:
- Visit CheatLab dashboard
- Find your username and auth_key
- Use them to initialize the client
cheat = Cheat("username", "auth_key")
# Or use custom base URL
cheat = Cheat("username", "auth_key", base_url="https://your-instance.com")
Usage Examples
Retrieving Messages
# Get latest message
latest = cheat.get("latest")
# Get by ID
message = cheat.get(47)
# Get by custom key
code = cheat.get("mykey")
# Get password-protected message
secret = cheat.get("mykey", password="secret123")
# Get full details (returns dict)
details = cheat.get("mykey", details=True)
print(details['id'])
print(details['text'])
print(details['created_at'])
Creating Messages
# Simple post
result = cheat.post("Hello World")
print(result) # {'success': True, 'id': 123}
# Post with custom key
cheat.post("My code snippet", key="snippet1")
# Post with author
cheat.post("Useful tip", key="tip", who="John")
# Post password-protected content
cheat.post(
"Private data",
key="secrets",
password="mypass",
protect_view=True, # Require password to view
protect_delete=True # Require password to delete
)
# Store file contents
with open("script.py", "r") as f:
content = f.read()
cheat.post(content, key="backup-script")
Deleting Messages
# Delete by ID
cheat.delete(47)
# Delete latest message
cheat.delete("latest")
# Delete by key
cheat.delete("mykey")
# Delete protected message
cheat.delete("mykey", password="secret123")
AI Assistant
# Ask AI a question (requires AI access on your account)
try:
response = cheat.ai("what is recursion?")
print(response)
except Exception as e:
print(f"AI error: {e}")
List Messages
# Get safe list of all messages (protected content hidden)
data = cheat.get_uidata()
print(f"Total messages: {data['count']}")
for msg in data['messages']:
text = msg.get('text') or '[protected]'
print(f"{msg['id']}: {text}")
# Get all messages (admin only)
all_data = cheat.get_all("admin_password")
Health Check
# Check if API is responding
status = cheat.ping()
print(status) # "pong"
Exception Handling
The client raises specific exceptions for different error scenarios:
from cheatlab import Cheat, AuthenticationError, APIError
cheat = Cheat("username", "auth_key")
try:
cheat.post("Test message")
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except APIError as e:
print(f"API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
API Reference
Cheat(username, auth_key, base_url="https://cheatlab.onrender.com")
Initialize the CheatLab client.
Parameters:
username(str): Your CheatLab usernameauth_key(str): Your authentication keybase_url(str, optional): API base URL
Methods
get(target, password=None, details=False)
Retrieve a message.
Parameters:
target(str|int): Message ID, key, or "latest"password(str, optional): Password for protected messagesdetails(bool, optional): Return full JSON details
Returns: str or dict
post(text, key=None, password=None, who=None, protect_view=False, protect_delete=False)
Create a new message.
Parameters:
text(str): Message contentkey(str, optional): Custom key (must be unique)password(str, optional): Protection passwordwho(str, optional): Author nameprotect_view(bool, optional): Require password to viewprotect_delete(bool, optional): Require password to delete
Returns: dict with success and id
delete(target, password=None)
Delete a message.
Parameters:
target(str|int): Message ID, key, or "latest"password(str, optional): Password if protected
Returns: str ("deleted" on success)
ai(prompt)
Ask the AI assistant.
Parameters:
prompt(str): Your question
Returns: str (AI response)
Note: Requires AI access on your account
get_uidata()
Get safe list of all messages.
Returns: dict with count and messages
get_all(admin_pass)
Get all messages (admin only).
Parameters:
admin_pass(str): Admin password
Returns: dict with count and messages
ping()
Health check.
Returns: str ("pong")
Common Use Cases
Store and Retrieve Code Snippets
# Store Python function
code = '''
def factorial(n):
return 1 if n <= 1 else n * factorial(n-1)
'''
cheat.post(code, key="factorial-py", who="Dev")
# Retrieve and use it
snippet = cheat.get("factorial-py")
exec(snippet)
print(factorial(5)) # 120
Quick Notes System
# Store a quick note
cheat.post("Remember to review PR #234", key="todo-today")
# Check it later
todo = cheat.get("todo-today")
print(todo)
# Delete when done
cheat.delete("todo-today")
Secure Credential Storage
# Store API key securely
cheat.post(
"API_KEY=xyz123abc456",
key="production-api-key",
password="secure_pass",
protect_view=True,
protect_delete=True
)
# Retrieve with password
credentials = cheat.get("production-api-key", password="secure_pass")
Backup Important Files
import os
# Backup a file
with open("important_config.json", "r") as f:
content = f.read()
cheat.post(
content,
key=f"backup-{os.path.basename(f.name)}",
who="AutoBackup"
)
# Restore later
restored = cheat.get("backup-important_config.json")
with open("restored_config.json", "w") as f:
f.write(restored)
Development
Install for Development
git clone https://github.com/yourusername/cheatlab-python.git
cd cheatlab-python
pip install -e .
Run Tests
pytest tests/
Requirements
- Python >= 3.7
- requests >= 2.25.0
License
MIT License
Support
- Documentation: CheatLab Docs
- Issues: GitHub Issues
Changelog
1.0.0 (2026-01-11)
- Initial release
- Full API support for all endpoints
- Exception handling
- Comprehensive documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cheatlab-1.0.0.tar.gz.
File metadata
- Download URL: cheatlab-1.0.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35bb382b834b4654dda70bfe67b046a9ffc1cc1de93659ca0a294a62dd290846
|
|
| MD5 |
5ea78279877e6504ec6cdda623296794
|
|
| BLAKE2b-256 |
d035ff94a3e63eb948c81af9cc01f5d889a3b7a77a7aa84bf509313f0e172013
|
File details
Details for the file cheatlab-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cheatlab-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d14c528e3e29e0adc2c8d7a6eb2db4af80b490ed076effe9e956d855881200
|
|
| MD5 |
bf987cf0df56a17c4958c40529f79f9d
|
|
| BLAKE2b-256 |
5e2459fa0ab2eef7bdccd881598e7a5cd561d51c65a57e95b6f82b201fbebb7a
|