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.1.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.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blockhouse-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 39455a463c63c6bac2279b38a6b11bf66276b6206989e06dbd5ce825c8362aa4
MD5 28e0ebe00002d133c590a525291d9752
BLAKE2b-256 62f3178f7d9eb1f73aed72b8a9b85cd223756826467671e4a77b9ccaede20319

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blockhouse-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa5168fccbbea88f482fb9ab6ba38423a2b7dc86591e62875daa4b40f97ebdbb
MD5 e06cce65fb501db4cbfad96c33e58704
BLAKE2b-256 6c654344da08bdabc439cded6abb2192318fdb0e48fef67621200fe1de9ae108

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