Skip to main content

Export Postman collections via CLI.

Project description

Postman Collection Exporter

Export your Postman collections via a simple CLI.


๐Ÿ“‘ Table of Content

โœจ Features

  • Export Multiple Collections: Export several Postman collections simultaneously with just a few commands.
  • Archive Collections in Known Formats: Archive exported Postman collections to formats like tar, zip, gztar, bztar, and xztar.
  • Asynchronous API Interaction: Leverages asyncio, httpx, and aiofiles for efficient, non-blocking communication with the Postman API.
  • Save Collections in JSON Format: Save Postman collections locally in a clean, standardized JSON format.
  • CLI Built with asyncclick Library: A powerful and user-friendly command-line interface, built with asyncclick to handle async operations gracefully.
  • Error Handling: Gracefully handles errors from the Postman API, ensuring that authentication issues or rate limits are reported clearly.
  • Modular and Extendable: The app's modular structure makes it easy to add new features or adjust behavior as needed.
  • Crontab Scheduling (Unix-based Systems): Automate exporting or archiving actions using crontab. This feature is only available on Unix-based systems and requires an additional dependency.
  • Logging: Logs CLI command results and errors to a user-specified log file (via the --log-path option).

๐Ÿš€ Usage

Export Collections

# Using Python module
python -m postman_collection_exporter.cli export --path /home/user/exports -n Collection1 -n Collection2 --api-key postman-api-key

# Using directly (--api-key is optional if POSTMAN_API_KEY is set)
export-collections --path /home/user/exports -n Collection1 -n Collection2 --api-key postman-api-key
  • -p, --path-to-collections: Directory, where exported collections will be located.
  • -n, --collection-names: Names of the Postman collections to be export.
  • -k, --api-key: Optional Postman API key for authentication. Overrides environment variable.
  • -l, --log-path: Path to the log file for the command output. [default: /home/username/crontab/cron.log]

Archive collections

# Using Python module
python -m postman_collection_exporter.cli archive --path-to-collections /home/user/exports --path-to-archive /home/user/archives -n My_Collections --archive-type tar

# Using directly (--api-key is optional if POSTMAN_API_KEY is set)
archive-collections --path-to-collections /home/user/exports --path-to-archive /home/user/archives -n My_Collections --archive-type tar
  • -c, --path-to-collections: Path to directory with collections being archived.
  • -a, --path-to-archive: Path to directory with an archive being created.
  • -n, --name: Name of the archive being created.
  • --archive-type: Type of an archive being created. [default:zip]
  • -l, --log-path: Path to the log file for the command output. [default: /home/username/crontab/cron.log]

Scheduling CLI actions

In order to use scheduling functionality it's necessary to install the package with an extra dependency:

pip install postman_collection_exporter"[schedule]"

# or install needed package later via
pip install python-crontab
# Using Python module
python -m postman_collection_exporter.cli set-schedule --action export --pattern "1 * * * *" --comment "Export Postman collections every hour."

# Using directly
set-schedule --action export --pattern "1 * * * *" --comment "Export Postman collections every hour."
  • -a, --action: Choose the Postman action to schedule. (export or archive at this time) [required]
  • -p, --pattern: Crontab pattern (e.g., "0 0 * * *" for daily at midnight). Must be written within quotes! [required]
  • -c, --comment: Comment added to the crontab entry (displayed next to the pattern) [required]
  • -u, --user: Username for the target crontab (default: current user). Assigning dynamically.
  • --dry-run: Show the crontab entry that would be created, without applying it.

โš™๏ธ Requirements

  • Python 3.11+

๐Ÿ“‘ Environment Variables

Set the Postman API key as an environment variable (optional):

export POSTMAN_API_KEY=<actual_api_key>

The script will fail gracefully if no API key is found.


๐Ÿ› ๏ธ Project Structure

.
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ src
โ”‚   โ””โ”€โ”€ postman_collection_exporter
โ”‚       โ”œโ”€โ”€ cli.py
โ”‚       โ”œโ”€โ”€ dependencies
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ utils.py
โ”‚       โ”œโ”€โ”€ enums.py
โ”‚       โ”œโ”€โ”€ exceptions.py
โ”‚       โ”œโ”€โ”€ exporters.py
โ”‚       โ”œโ”€โ”€ helpers.py
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ logging
โ”‚       โ”‚   โ”œโ”€โ”€ config.py
โ”‚       โ”‚   โ””โ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ scheduling
โ”‚       โ”‚   โ”œโ”€โ”€ cli.py
โ”‚       โ”‚   โ”œโ”€โ”€ crontab_helpers.py
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ””โ”€โ”€ utils.py
โ”‚       โ””โ”€โ”€ structures.py
โ””โ”€โ”€ tests
    โ”œโ”€โ”€ fixtures
    โ”‚   โ”œโ”€โ”€ test_data_collection_1.json
    โ”‚   โ””โ”€โ”€ test_data_collection_2.json
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ mocks.py
    โ”œโ”€โ”€ test_crontab_helpers.py
    โ””โ”€โ”€ test_helpers.py

๐Ÿงน TODO

  • Add unit tests for archiving
  • Add unit tests for exporting
  • Add logging to CLI command
  • Add logging to helpers functions
  • Add unit tests for scheduling
  • Add GitHub Actions CI
  • Add logging

๐Ÿ“œ License

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

๐Ÿ‘ค Authors

Sergey Vernigora volt.awp.dev@gmail.com

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

postman_collection_exporter-0.0.5.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

postman_collection_exporter-0.0.5-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file postman_collection_exporter-0.0.5.tar.gz.

File metadata

File hashes

Hashes for postman_collection_exporter-0.0.5.tar.gz
Algorithm Hash digest
SHA256 c9f1379e9d7dc3566b59f362cdb80322f84cb9e13d40dd8ed5d7d874a4434c46
MD5 030faf099d3f2389504ffdb3fe747b4a
BLAKE2b-256 fc79187eb245edad6368a8a5e5a21c021fb07eabe5a478c7612e7dae836acce1

See more details on using hashes here.

Provenance

The following attestation bundles were made for postman_collection_exporter-0.0.5.tar.gz:

Publisher: release.yaml on sergey-vernyk/PostmanCollectionExporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postman_collection_exporter-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for postman_collection_exporter-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0d6d4f7fcd282a21932801b851eaee761b567034076aec47e04af6db8c892f6a
MD5 0c6b74b866b793fbbe04969d932d6710
BLAKE2b-256 33f3529c1981eb68bfad8decfff48cef4cfa997fb0dea0741f22d060ce603bcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for postman_collection_exporter-0.0.5-py3-none-any.whl:

Publisher: release.yaml on sergey-vernyk/PostmanCollectionExporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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