Reverse engineered Fragment API that mimics the official webclient
Project description
python-fragment
An unofficial Python library for interacting with Fragment (Python 3.9+). The library scrapes Fragment's HTML pages and exposes a clean, fully typed interface.
Features
- Both synchronous and asynchronous clients
- Fast HTML parsing powered by selectolax
- Fully typed - all returned data is described with
TypedDictschemas - Automatic retries on network failures with exponential back-off
Installation
pip install python-fragment
Quick Start
Async client
import asyncio
import fragment
async def main():
async with fragment.AsyncClient() as client:
# Search usernames currently on auction
usernames = await client.search_usernames(
query="crypto",
filter="auction",
sort="price_desc"
)
for u in usernames[:3]:
print(u)
# {
# 'username': 'crypto',
# 'status': 'auction',
# 'value': 15000.0,
# 'datetime': '2024-08-01T12:00:00+00:00',
# 'is_resale': False
# }
asyncio.run(main())
Sync client
import fragment
with fragment.Client() as client:
# Detailed info for a specific username
info = client.username_info("durov")
print(info["status"])
print(info["bid_history"])
print(info["ownership_history"])
Proxy Usage
A proxy can be set for the entire client session or overridden per individual request. The interface is identical for both AsyncClient and Client.
Client-level proxy
import fragment
PROXY = "http://{user}:{password}@{host}:{port}"
# Async
async with fragment.AsyncClient(proxy=PROXY) as client:
print(await client.username_info("crypto"))
# Sync
with fragment.Client(proxy=PROXY) as client:
print(client.username_info("crypto"))
Per-request proxy
import fragment
PROXY = "http://{user}:{password}@{host}:{port}"
# Async
async with fragment.AsyncClient() as client:
print(await client.username_info("crypto", proxy=PROXY))
# Sync
with fragment.Client() as client:
print(client.username_info("crypto", proxy=PROXY))
Error Handling
import fragment
from fragment.errors import FragmentHTTPError, ParserError
async with fragment.AsyncClient() as client:
try:
info = await client.username_info("someusername")
except FragmentHTTPError as e:
print(f"HTTP error: {e}")
except ParserError as e:
print(f"Failed to parse Fragment HTML: {e}")
FragmentHTTPError - raised when the server returns a non-OK response.
ParserError - raised when the Fragment page structure has changed and data cannot be extracted.
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 python_fragment-0.4.2.tar.gz.
File metadata
- Download URL: python_fragment-0.4.2.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9c515e495a963a6f689103fb692619166371212f5e0240a436abbf3ff288d5a
|
|
| MD5 |
3390bf75bc59effc3a3cd37a6dac2795
|
|
| BLAKE2b-256 |
4331447b4683bae179c0c92a5279a982b7a39da6d1ed3ab142124b00b2f71f66
|
File details
Details for the file python_fragment-0.4.2-py3-none-any.whl.
File metadata
- Download URL: python_fragment-0.4.2-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8c27993aa738bac1731d3eb528f221bcdab327c705b86cfc1427944ea614f36
|
|
| MD5 |
29e0a41b90d8bef54d425c073a5fe72b
|
|
| BLAKE2b-256 |
8653636d1d2ba9d9ddb95174cfa273ab69b43be870f43487d41b2eb431fc3754
|