Skip to main content

python-squarelet

A Python wrapper for Squarelet, allowing for authentication with MuckRock systems like MuckRock Requests and DocumentCloud.

Features

  • Token-based Authentication: Easily authenticate with MuckRock services using username/password or refresh tokens.
  • Rate Limiting: Automatically applies rate limiting to prevent exceeding API request limits.
  • Automatic Token Refresh: Seamlessly refresh your access tokens when expired without manual intervention. It detects that your access token is about to expire before making the request so it eagerly refreshes.
  • Retry Logic: Built-in automatic retries for failed requests, ensuring robust interaction with MuckRock services.
  • API Request Handling: Send GET, POST, PUT, DELETE, and other HTTP requests to MuckRock’s API with an easy-to-use interface.
  • Customizable Request Headers: Extend or modify request parameters (like headers) through flexible client configuration.
  • Error Handling: Provides detailed error handling with custom exceptions for API errors, credentials issues, and missing resources.

Installation

$ pip install python-squarelet

Usage

# If you intend on accessing MuckRock requests, the base_uri would be https://www.muckrock.com/api_v1/ or https://www.muckrock.com/api_v2/
base_uri="https://api.www.documentcloud.org/api/"
from squarelet import SquareletClient
# Authenticating with Squarelet using your credentials
client = SquareletClient(base_uri=base_uri, username="your_username", password="your_password")
# Example API call that gets data about your DocumentCloud account.
my_user = client.request("get", "users/me/")
# Print the response data about your DocumentCloud account. 
print(my_user.text) 

Generally, it is safer to access your username as local environment variables using os.environ instead of specifying your username and password as strings, especially if publishing this code anywhere. After setting your local environment variables SQ_USERNAME and SQ_PASSWORD with your credentials, you can access them like so.

username = os.environ["SQ_USERNAME"]
password = os.environ["SQ_PASSWORD"]

Running tests

You can run tests from the project root by running:

$ pytest src/squarelet/tests.py

Metadata

Release files for python-squarelet 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-squarelet 0.6.0
File Size Uploaded Provenance Actions
python_squarelet-0.6.0.tar.gz 19.7 kB Without provenance Details for python_squarelet-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-squarelet 0.6.0
File Interpreter ABI Platform Actions
python_squarelet-0.6.0-py3-none-any.whl Python 3 none any Details for python_squarelet-0.6.0-py3-none-any.whl

Total release size: 40.7 kB

Release files / python_squarelet-0.6.0.tar.gz

Download URL python_squarelet-0.6.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a163dd05814de6a499339b42c4a120ab1a3767ee6fbfee3ec4f3f3a39d5f848f
BLAKE2b-256 checksum
How to use checksums
4a7a8a8b072bb3681f8181463c4aeb475974efe10e26754a1633b3dc6ccb268a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / python_squarelet-0.6.0-py3-none-any.whl

Download URL python_squarelet-0.6.0-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09fa42e42a75e31ad683486790a0dfbcc1f4e8651a350c76553024022e7151b2
BLAKE2b-256 checksum
How to use checksums
6bd11663f5229754d8ee33da176928c32d036fb9a4c6b9b160a9d0f473a3c95b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for python-squarelet 0.6.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page