Skip to main content

Python SDK for working with the Nova Post API

Project description

Nova_Post

A Python wrapper for the Nova Poshta API, providing an easy-to-use interface for interacting with Nova Poshta's logistics and tracking services.

Features

  • Address management: create, update, delete addresses, and retrieve city, warehouse, and street directories.
  • Counterparty management: manage sender/receiver contacts and related information.
  • Internet document (waybill) management: create, update, delete, and track shipments.
  • Common API methods: retrieve time intervals, cargo types, packaging options, and service types.
  • Shipment tracking: track parcels via document numbers and phone numbers.

Installation

You can install Nova_Post via pip:

pip install nova-post

Usage

Initialization

from nova_post.api import NovaPostApi

api = NovaPostApi(api_key="your_api_key")

Note: You can obtain your API key from your business account at Nova Poshta Business Cabinet.

Address API

from nova_post.models.address import GetCitiesRequest

request_data = GetCitiesRequest(FindByString="Київ", Limit=5)
cities = api.address.get_cities(request_data)
print(cities)

Shipment Tracking

from nova_post.models.tracking import TrackingRequest

tracking_request = TrackingRequest(DocumentNumber="20400048799000")
tracking_info = api.tracking.track_parcel(tracking_request)
print(tracking_info)

Creating a Waybill (Internet Document)

from nova_post.models.internet_document import SaveInternetDocumentRequest

request = SaveInternetDocumentRequest(
    PayerType="Sender",
    PaymentMethod="Cash",
    DateTime="2025-03-18",
    CargoType="Cargo",
    Weight=5.0,
    ServiceType="WarehouseWarehouse",
    SeatsAmount=1,
    Description="Test Cargo",
    Cost=500,
    CitySender="sender_city_ref",
    Sender="sender_ref",
    SenderAddress="sender_address_ref",
    ContactSender="contact_sender_ref",
    SendersPhone="contact_sender_phone",
    CityRecipient="recipient_city_ref",
    Recipient="recipient_ref",
    RecipientAddress="recipient_address_ref",
    ContactRecipient="contact_recipient_ref",
    RecipientsPhone="contact_recipient_phone"
)

document = api.internet_document.save_internet_document(request)
print(document)

Note: To determine Sender, Recipient, and their parameters (ref, address, etc.), use the counterparty adapter.

Documentation: All adapters follow the official Nova Poshta API documentation: Nova Poshta API Documentation.

Issues: Report bugs or suggest features at GitHub Issues.

Error Handling

Nova_Post raises NovaPostApiError when the API returns an error or when a request fails due to timeouts or invalid responses. Example:

from nova_post.exceptions import NovaPostApiError

try:
    tracking_info = api.tracking.track_parcel(tracking_request)
    print(tracking_info)
except NovaPostApiError as e:
    print(f"API error occurred: {e}")

Logging

Nova_Post includes logging for API requests and responses. By default, logs are sent to the standard output. You can configure logging in logger.py to redirect logs to a file or another logging service:

import logging
from nova_post.logger import logger

logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler("nova_post.log")
logger.addHandler(file_handler)

Configuration

Nova_Post supports optional configurations such as request timeouts and retries. These settings can be adjusted within the NovaPostApi class:

api = NovaPostApi(api_key="your_api_key")
api.DEFAULT_TIMEOUT = 15  # Increase timeout to 15 seconds

Supported Python Versions

Nova_Post is compatible with Python 3.9 and above.

Running Tests

To run unit and integration tests, use:

pytest tests/

Environment Variables

The library uses an API key, which should be set as an environment variable:

export NOVA_POST_API_KEY="your_api_key"

Planned Performance Improvements

To enhance performance, caching mechanisms will be introduced to store frequently used API responses (e.g., city directories and service lists). This will reduce redundant API calls and improve response times. Additional optimizations include connection pooling for HTTP requests.

Contributing

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m 'Add new feature').
  4. Push to the branch (git push origin feature-name).
  5. Open a Pull Request.

License

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

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

nova_post-0.2.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

nova_post-0.2.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nova_post-0.2.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nova_post-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7951f4b2a24c90a8c2e93d5ca858db13791d7ca3c7d7226d6df395a514bea399
MD5 cb59a487d24626e7fb50607462d9cee7
BLAKE2b-256 be37491c34e94171c4e957c7d936cba5c269448ca847eec2cda3a3a1ac45c110

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nova_post-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nova_post-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31a61cb95428f7740c5400f2ece9460dfc7f28f28696d53b662ddc6a36d69536
MD5 fa7cc0316927f2114ff5e5baddce50ce
BLAKE2b-256 6a4fd53fa464aa168189fabbb7c576d791011f5b9cc98a7dfab5616582515e07

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