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.3.tar.gz (5.1 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.3-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: blockhouse-1.0.3.tar.gz
  • Upload date:
  • Size: 5.1 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.3.tar.gz
Algorithm Hash digest
SHA256 23876fea1630f2c5bee1dd1baa5c2f02659e837e0924ca4933c4c79336eba51e
MD5 d9694738ca845d3d6fa1e1d9d213ccf2
BLAKE2b-256 48e132990499b08b5f9f02c47f54155634e394e75a2766ef1cdc0ed6b4648fb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: blockhouse-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d4f856e8ce5afd3fc2bfd1ed389ce6c9bf937ca646f227b4f200f43f3daa456
MD5 2407df39e7e4ffa57c254263e25aa5e7
BLAKE2b-256 e44a08f18f581fd580a111ca1b99afe6aabbf2ecd4e81dc3d814be781e70d85d

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