Python client library for the Ulfom API
Project description
Ulfom
A Python client library for interacting with the Ulfom API. This library provides both synchronous and asynchronous interfaces.
Installation
pip install ulfom
Usage
Basic Client Usage
Synchronous Client
from ulfom import UlfomClient
# Initialize the client
client = UlfomClient(
base_url="https://www.ulfom.com/api/v1",
api_key="your-api-key" # Optional
)
# Make requests
response = client.get("/endpoint")
data = client.post("/endpoint", json={"key": "value"})
Asynchronous Client
from ulfom import AsyncUlfomClient
async def main():
# Initialize the client
async with AsyncUlfomClient(
base_url="https://www.ulfom.com/api/v1",
api_key="your-api-key" # Optional
) as client:
# Make requests
response = await client.get("/endpoint")
data = await client.post("/endpoint", json={"key": "value"})
# Run the async code
import asyncio
asyncio.run(main())
Using Helper Classes
The library provides helper classes to make common operations easier:
URL Processing
from ulfom import UlfomClient, URLHelper
client = UlfomClient(base_url="https://www.ulfom.com/api/v1", api_key="your-api-key")
url_helper = URLHelper(client)
# Process a URL
result = url_helper.process_url(service="extractor", url="https://example.com")
# Get content by hash
content = url_helper.get_by_hash(service="extractor", domain="example.com", hash="abc123")
Task Management
from ulfom import UlfomClient, TaskHelper
# Initialize task helper with custom polling settings
task_helper = TaskHelper(
client,
poll_interval=2.0, # Check every 2 seconds
timeout=300 # Timeout after 5 minutes
)
# Create a task and wait for completion
try:
result = task_helper.create_and_wait(
service="sitemap_crawl",
url="https://example.com",
parameters={"max_pages": 100},
poll_interval=1.0, # Override default poll interval
timeout=60 # Override default timeout
)
print("Task completed:", result)
except TimeoutError:
print("Task timed out")
except Exception as e:
print("Task failed:", str(e))
# Alternatively, create a task and wait for it separately
task = task_helper.create_task(
service="sitemap_crawl",
url="https://example.com"
)
try:
status = task_helper.wait_for_task(
service="sitemap_crawl",
task_id=task["task_id"]
)
print("Task completed:", status)
except TimeoutError:
print("Task timed out")
except Exception as e:
print("Task failed:", str(e))
Service Discovery
from ulfom import UlfomClient, ServiceHelper
client = UlfomClient(base_url="https://www.ulfom.com/api/v1", api_key="your-api-key")
service_helper = ServiceHelper(client)
# List available services
url_services = service_helper.list_url_services()
task_services = service_helper.list_task_services()
Async Helper Classes
from ulfom import AsyncUlfomClient, AsyncURLHelper, AsyncTaskHelper, AsyncServiceHelper
async def main():
async with AsyncUlfomClient(
base_url="https://www.ulfom.com/api/v1",
api_key="your-api-key"
) as client:
# URL Processing
url_helper = AsyncURLHelper(client)
result = await url_helper.process_url(service="extractor", url="https://example.com")
# Task Management
task_helper = AsyncTaskHelper(client)
task = await task_helper.create_task(
service="sitemap_crawl",
url="https://example.com"
)
# Service Discovery
service_helper = AsyncServiceHelper(client)
services = await service_helper.list_url_services()
asyncio.run(main())
Async Task Polling
The async task helper provides convenient methods for waiting for task completion:
from ulfom import AsyncUlfomClient, AsyncTaskHelper
async def main():
async with AsyncUlfomClient(
base_url="https://www.ulfom.com/api/v1",
api_key="your-api-key"
) as client:
# Initialize task helper with custom polling settings
task_helper = AsyncTaskHelper(
client,
poll_interval=2.0, # Check every 2 seconds
timeout=300 # Timeout after 5 minutes
)
# Create a task and wait for completion
try:
result = await task_helper.create_and_wait(
service="sitemap_crawl",
url="https://example.com",
parameters={"max_pages": 100},
poll_interval=1.0, # Override default poll interval
timeout=60 # Override default timeout
)
print("Task completed:", result)
except asyncio.TimeoutError:
print("Task timed out")
except Exception as e:
print("Task failed:", str(e))
# Alternatively, create a task and wait for it separately
task = await task_helper.create_task(
service="sitemap_crawl",
url="https://example.com"
)
try:
status = await task_helper.wait_for_task(
service="sitemap_crawl",
task_id=task["task_id"]
)
print("Task completed:", status)
except asyncio.TimeoutError:
print("Task timed out")
except Exception as e:
print("Task failed:", str(e))
asyncio.run(main())
Features
- Both synchronous and asynchronous interfaces
- Helper classes for common operations
- Automatic session management
- Type hints for better IDE support
- Configurable timeouts
- Bearer token authentication support
- Async task polling with configurable intervals and timeouts
- Synchronous task polling with configurable intervals and timeouts
Development
- Clone the repository
- Install dependencies:
poetry install - Run tests:
poetry run pytest
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Support
For support, please open an issue in the GitHub repository.
Project details
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 ulfom-0.1.4.tar.gz.
File metadata
- Download URL: ulfom-0.1.4.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b544af5d59df70996177828f5519b7f0c292c4c154365efd6fd1af7801d63af6
|
|
| MD5 |
edaedea44d1f75e0a9c6c6fa1965f496
|
|
| BLAKE2b-256 |
2fa06ced0fab83302cb5440a0ec1fb70d1ed14d7d637c0e68f74105df5450f55
|
Provenance
The following attestation bundles were made for ulfom-0.1.4.tar.gz:
Publisher:
publish.yml on ulfom/ulfom-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ulfom-0.1.4.tar.gz -
Subject digest:
b544af5d59df70996177828f5519b7f0c292c4c154365efd6fd1af7801d63af6 - Sigstore transparency entry: 205417307
- Sigstore integration time:
-
Permalink:
ulfom/ulfom-python@d04b26f33e23ce6fea5739d5b5b5c2ba03ed4ace -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ulfom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d04b26f33e23ce6fea5739d5b5b5c2ba03ed4ace -
Trigger Event:
release
-
Statement type:
File details
Details for the file ulfom-0.1.4-py3-none-any.whl.
File metadata
- Download URL: ulfom-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc68fc0046e76fb5a6ce31bb8463ba6246c96221df6f32b460f4c56954473e4c
|
|
| MD5 |
bfa23cefc87881e76197cc94c5926a3e
|
|
| BLAKE2b-256 |
c738a7f145f6b98b42760273c247bfeec6b044a3bf67b44a9e244ab8200d4908
|
Provenance
The following attestation bundles were made for ulfom-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on ulfom/ulfom-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ulfom-0.1.4-py3-none-any.whl -
Subject digest:
bc68fc0046e76fb5a6ce31bb8463ba6246c96221df6f32b460f4c56954473e4c - Sigstore transparency entry: 205417308
- Sigstore integration time:
-
Permalink:
ulfom/ulfom-python@d04b26f33e23ce6fea5739d5b5b5c2ba03ed4ace -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ulfom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d04b26f33e23ce6fea5739d5b5b5c2ba03ed4ace -
Trigger Event:
release
-
Statement type: