Skip to main content

Web-Library for Python

Project description

WApi: Web-Library for Python

PyPI version

Libraries used:

Features

  • Routes
  • Serialization
  • Params
    • Auto-Complete
    • Unpaking

Installation

You can install the latest version with the command:

pip install whaox-wapi

• Routes #routes

You can create paths as you like, splitting your client into modules

@Route("https://example.com")
class WApi:
    service = Service()

@Route("/wapi")
class Service:

  @Route("/path")
  @GET("/")
  def get(self): pass	

  @POST("/path")
  def post(self): pass
wapi = WApi()
wapi.service.get()
# eq
requests.get("https://example.com/wapi/path/")

• Serialization

The library deserializes the received data according to the type that you specify in the _T parameter of the decorator.

NOTE: The specified type must be json serializable - these are the base types and classes marked with the @dataclass annotation

@dataclass
class Person:
	name: str

@Route("https://example.com")
class WApi:

  @GET("/person", _T=Person)
  def person(self) -> Person: pass

  @GET("/people", _T=List[Person])
  def people(self) -> List[Person]: pass
api = WApi()
person = api.person()

print(person.name)
>>> "John"

• Params

You can flexibly add parameters to the path using {}. The library uses formatting from the standard library.

@Route("https://example.com")
class WApi:

  @GET("/path?name={name}")
  def route(self, name: str): pass

• • Auto-complete

If you want the parameters to be set automatically, you can switch the auto flag to True.

NOTE: if auto=True, you must pass named parameters so that they are added to the path.

@Route("https://example.com")
class WApi:

  @GET("/path", auto=True) # eq /path?name={name}
  def route(self, name: str): pass

• • Unpacking

In order not to pass a lot of parameters, you can pass one by calling it body, it will automatically decompose into parameters, to do this, set the unpack flag to True.

NOTE: Nested non-standard type parameters are not decomposed.

@dataclass
class Person:
  name: str
  age: int  


@Route("https://example.com")
class WApi:

  @GET("/path", auto=True, unpack=True) # eq /path?name={name}&age={age}
  def route(self, body: Person): pass

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

whaox-wapi-1.0.30.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file whaox-wapi-1.0.30.tar.gz.

File metadata

  • Download URL: whaox-wapi-1.0.30.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for whaox-wapi-1.0.30.tar.gz
Algorithm Hash digest
SHA256 ef02c5933d2fc4dbe719ce43a933ac49a1aa7b3e003665e7dd873c98a2b4a028
MD5 e2c0fd86cf82c62ad68ba3b52dbe4cde
BLAKE2b-256 b7aacfbdecc037373e66f8fcf2384f4c505676320a106545ddc5e488b9e7a98d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page