Skip to main content

A Python SDK for interacting with JSONPlaceholder and your custom APIs.

Project description

Guide doc for Packaging SDK API for PyPI Deployment

sdk.py is for interacting with the JSONPlaceholder API. This SDK provides functions to fetch todos, posts, comments, albums, photos, and users. It supports both library usage and command-line interface (CLI) for quick data access.

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Development and Packaging
  5. Building the Package
  6. Publishing to TestPyPI and PyPI
  7. Testing the Package Locally
  8. Automating Deployment with GitHub Actions
  9. License
  10. Contributing
  11. Support

Features

  • Fetch todos, posts, comments, albums, photos, and users from JSONPlaceholder.
  • Command-line support to quickly access data.
  • Scalable and reusable in other Python projects.
  • Simple installation using pip.

Installation

To install the package after publishing it to PyPI:

pip install sdk-api-package

For local testing before deployment, install the package from your local dist/ folder:

pip install dist/sdk_api_package-0.1.0-py3-none-any.whl

Usage

Using as a Python Library

from sdk import get_todos, get_users

# Fetch and print all todos
get_todos()

# Fetch and print all users
get_users()

Using the Command-Line Interface (CLI)

python -m sdk [command] [id]

Available Commands:

todos [user_id] – Fetch todos for a specific user or all users.

posts [user_id] – Fetch posts for a specific user or all users.

comments [post_id] – Fetch comments for a specific post or all posts.

albums [user_id] – Fetch albums for a specific user or all albums.

photos [album_id] – Fetch photos for a specific album or all albums.

users – Fetch and print all users.

Examples:

# Fetch all todos
python -m sdk todos

# Fetch posts for user ID 2
python -m sdk posts 2

Development and Packaging

Project Structure:

Copy code
sdk-package/

├── PythonSDK/
   ├── __init__.py          # Initialize package
   └── sdk.py               # Your SDK code

├── LICENSE                  # License information
├── README.md                # Documentation
├── setup.cfg                # Package metadata and configurations
├── pyproject.toml           # Build system configurations
├── MANIFEST.in              # Optional: Include non-code files
└── dist/                    # Distribution files after building

Building the Package

Install the required tools:

pip install build

Build the package:

python -m build

This will create .tar.gz and .whl files in the dist/ directory.

Publishing to TestPyPI and PyPI

Create an account on PyPI and TestPyPI.

  1. Install Twine:
pip install twine
  1. Upload to TestPyPI:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
  1. Upload to PyPI:
twine upload dist/*

Verify the package on PyPI or TestPyPI.

Testing the Package Locally

After building the package, test it locally:

  1. Install the package:
pip install dist/sdk_api_package-0.1.0-py3-none-any.whl
  1. Test the library:
from sdk import get_users
get_users()

Automating Deployment with GitHub Actions

You can automate the deployment process using GitHub Actions.

Create a .github/workflows/python-publish.yml file:

name: Publish Python Package

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.x

      - name: Install dependencies
        run: |
          pip install build twine

      - name: Build and publish
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          python -m build
          twine upload dist/*

Add PyPI Token to GitHub Secrets:

Go to your GitHub repository. Navigate to Settings > Secrets > Actions. Add a new secret with the name PYPI_API_TOKEN and paste your PyPI token.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Support

If you encounter any issues or have questions, feel free to open an issue on GitHub.

Changelog

Version 0.1.0 Initial release with: Functions for todos, posts, comments, albums, photos, and users Command-line interface (CLI) support

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

blockhouse-1.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

blockhouse-1.0.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file blockhouse-1.0.2.tar.gz.

File metadata

  • Download URL: blockhouse-1.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for blockhouse-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e45811e8a0d74a4aa6ae950c6c9ebac353a9942627473a07874d5ca1715ce7b9
MD5 dc6f8f81d15a20ae2c53894fc768b0e2
BLAKE2b-256 7de793feb78b782035d3114959d269afd7149dca7e70aa88a488ec79cce76c4b

See more details on using hashes here.

File details

Details for the file blockhouse-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: blockhouse-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for blockhouse-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4d3a8ca959af15175d82501e222ded4cdd7c7f75638c7fb01f85ca9f8d3cc970
MD5 d7b6b83af7257b91e9226df7fa8d4648
BLAKE2b-256 bd454c1b9751f30091ccaf40df677ad3f56d14ca55415c4c26ba1918cd1aafd3

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