Skip to main content

Python library that handles token authentication for MuckRock and DocumentCloud

Project description

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.
  • 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"]

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

python_squarelet-0.2.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_squarelet-0.2.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file python_squarelet-0.2.1.tar.gz.

File metadata

  • Download URL: python_squarelet-0.2.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for python_squarelet-0.2.1.tar.gz
Algorithm Hash digest
SHA256 885a4170a3b0cc33432466134141fc7efc827fd2fd3cbc07014505c4f8725dab
MD5 627b4f61d3005bd5f9ecfa7b000be3ff
BLAKE2b-256 0290bff02e5798ba6f90ace3ded90a81a4de232027192ee0f82c9f3f0de26592

See more details on using hashes here.

File details

Details for the file python_squarelet-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_squarelet-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5cd256313aeb944eabf75079c4c5b9a0fcc6e735cf88cb0ad758f1b7f2af66a
MD5 a88b3436308dd4d48973d1c2d1fda0c9
BLAKE2b-256 6a83fdc3dbafa7fe7df72f61d345cd3c7a7e1c1377570f2fd8875e6a6bef0192

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page