pieforhead
A python wrapper for the PieFed API supporting both synchronous and asynchronous usage. This is an early work in progress, and few endpoints are supported yet.
Usage Notes
In general, successful requests to the server should return a dict with the server's json response with very few exceptions (which should be type-hinted). Due to the alpha nature of the PieFed API, the maintenance burden of creating and updating response models as features/fields are added to the API is a burden that I don't want to take on at this time. Please refer to the official PieFed OpenAPI specification (stable version, development version) to see what your code should expect as a response.
By default, exceptions will be raised if something goes wrong (e.g. malformed request, network timeout, 5XX errors, etc.) to provide a trace. However, to suppress these exceptions, you can pass the raise_exceptions=False keyword argument when instantiating your client. This will cause a returned value of None instead of raising an exception. Please make sure that your code handles such a case appropriately.
Synchronous Client Usage
Users familiar with network libraries like requests would probably be most familiar with synchronous usage. However, to make network requests a bit more efficient, this library makes use of Clients within httpx where you can take advantage of connection pooling for multiple network requests. This means that when you instantiate a PieFed class, it is best practice to close it when you are done with it. Here are a couple examples that show how this can be done.
These snippets all do the same three things:
- Create a
PieFedobject with the given instance url (this creates the client) - Log in using a username and password
- Close the client after we no longer need it
Closing it manually using the close function:
from pieforhead import PieFed
piefed = PieFed("https://instance.tld")
piefed.log_in("username", "password")
piefed.close()
Using a context manager (a with block):
# Inside a context manager
with PieFed("https://instance.tld") as piefed:
piefed.log_in("username", "password")
# The connection is closed after leaving the `with` block
Using a callback that ensures the close function is called when execution has ended:
# Registering an event handler
import atexit
piefed = PieFed("https://instance.tld")
atexit.register(piefed.close) # Automatically closes the client at program termination
Asynchronous Client Usage
To use this libray in an async manner, there is a separate client, PieFedAsync that should be used. Everything else should work exactly the same as the synchronous client, except that results will need to be awaited.
Here is a snippet that does the same three actions as outlined above for the synchronous client, but using the PieFedAsync client.
# Put things in an async function so that we can use the await keyword
async def main():
piefed_async = PieFedAsync("https://instance.tld")
await piefed_async.log_in("username", "password") # Notice the await keyword
await piefed_async.close()
# Start the event loop and execute the async function
asyncio.run(main())
Similar to the synchronous client, you can also use a context handler to automatically close the async client:
async def main():
async with PieFedAsync("https://instance.tld") as piefed_async:
await piefed_async.log_in("username", "password")
# Client is closed automatically once outside the context handler
# Start the event loop and execute the async function
asyncio.run(main())
Endpoint Coverage
This project is in an early stage. Here is a high level summary of where things stand with implementing the wrapper around different PieFed API endpoint groups:
| Endpoint Group | Sync Client | Async Client | Notes |
|---|---|---|---|
| Site | ✅ | ✅ | Instance chooser endpoints unimplemented |
| Upload | ✅ | ✅ | |
| User | ✅ | ✅ | Register endpoint unimplemented |
| Post | ✅ | ✅ | Experimental post/list2 endpoint unimplemented |
| Comment | ✅ | ✅ | |
| Community | ✅ | ✅ | |
| Feed | ✅ | ✅ | |
| Topic | ✅ | ✅ | |
| Private Message | ✅ | ✅ | |
| Admin | ✅ | ✅ | |
| Misc. | ✅ | ✅ |
Metadata
Release files for pieforhead 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pieforhead-0.0.7.tar.gz | 76.5 kB | Without provenance | Details for pieforhead-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pieforhead-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for pieforhead-0.0.7-py3-none-any.whl |
Total release size: 100.9 kB
Release files / pieforhead-0.0.7.tar.gz
| Download URL | pieforhead-0.0.7.tar.gz |
|---|---|
| Size | 76.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4955851b33b79c6265cfa7627aeb078e8353ee65187dbbbd128966a2ce179a9c
|
|
BLAKE2b-256 checksum How to use checksums |
66abe36c5fd7a65bbe66095df778d28ce62876aa07ea77a4a5b61bdac909ea3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / pieforhead-0.0.7-py3-none-any.whl
| Download URL | pieforhead-0.0.7-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d832dced12b7fd03d2b79a55b2995ed86feb8912a405b64f3bf3d735fd40e6e7
|
|
BLAKE2b-256 checksum How to use checksums |
9c74f52562dbcd5b78e6f811ce014226f4cab612d5b67331e7dd805884fdeb19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Security for pieforhead 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.