Skip to main content

WApi: Library to simplify api development

PyPI version

Libraries used:

Features

  • Routes
  • Serialization
  • Asynchrony
  • Request Params
    • Smart substitution

Installation

You can install the latest version with the command:

pip install whaox-wapi

• Routes

You can create paths as you like, splitting your api-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"

• Asynchrony

You can make the query asynchronous simply by adding an async keyword.

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

  @GET("/person")
  async def person(self): pass
person = await api.person(params={"id": 1})

• Request Params

You can flexibly add parameters to request passing relevant attributes.

@dataclass
class GetPersonRequest:
  id: int
  
@dataclass
class CreatePersonRequest:
  name: str


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

  @POST("/person")
  def create_person(self, body: dict): pass
	
  @Route("/person") 
  @GET("/")
  def person(self, params: GetPersonRequest | dict): pass
api.person(params={"id": 1})
api.create_person(body={"name": "john"})
# or
api.person(params=GetPersonRequest(1))
api.create_person(params=CreatePersonRequest("john"))

• • Smart substitution

The library understands what variables you used during formatting and will not substitute them into the path parameters.

@dataclass
class GetPersonRequest:
    id: int
    preview: bool

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

  @Route("/person")
  @GET("/{id}")
  def person(self, params: GetPersonRequest): pass
person = api.person(params=GetPersonRequest(1, true))
# eq
person = requests.get("https://example.com/person/1?preview=true")

Metadata

Release files for whaox-wapi 1.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whaox-wapi 1.1.6
File Size Uploaded
whaox-wapi-1.1.6.tar.gz 7.5 kB Details

Release files / whaox-wapi-1.1.6.tar.gz

Download URL whaox-wapi-1.1.6.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7cd368a53c32d1973c3f84bc7dee579de62d5c4cc90edd8478cfd0e2aefa3435
BLAKE2b-256 checksum
How to use checksums
cd7236b1ab74b72858c8ed973db6695742eec7879b3a36be3130066acbb49d28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.1.6 This release

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.31

1 release file

1.0.30

1 release file

1.0.29

1 release file

1.0.28

1 release file

1.0.27

1 release file

1.0.26

1 release file

1.0.25

1 release file

1.0.24

1 release file

1.0.23

1 release file

1.0.22

1 release file

1.0.21

1 release file

1.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page